      SUBROUTINE beta_1(d_i0,d_t1,d_tra1,d_tra2,d_trb1,d_trb2,d_trc1,d_t
     &rc2,d_v2,d_y1,d_y2,k_i0_offset,k_t1_offset,k_tra1_offset,k_tra2_of
     &fset,k_trb1_offset,k_trb2_offset,k_trc1_offset,k_trc2_offset,k_v2_
     &offset,k_y1_offset,k_y2_offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( )_vtratrctrby + = -1 * Sum ( p9 h8 ) * y ( h8 p9 )_y * i1 ( p9 h8 )_vtratrctrb
C         i1 ( p9 h8 )_vtratrctrb + = 1 * Sum ( h4 ) * trb ( p9 h4 )_trb * i2 ( h4 h8 )_vtratrc
C             i2 ( h4 h8 )_vtratrc + = 1 * Sum ( p5 ) * trc ( p5 h8 )_trc * i3 ( h4 p5 )_vtra
C                 i3 ( h4 p5 )_vtra + = 1 * Sum ( h2 p1 ) * tra ( p1 h2 )_tra * v ( h2 h4 p1 p5 )_v
C             i2 ( h4 h8 )_vtrctra + = 1 * Sum ( p1 ) * tra ( p1 h8 )_tra * i3 ( h4 p1 )_vtrc
C                 i3 ( h4 p1 )_vtrc + = 1 * Sum ( h6 p5 ) * trc ( p5 h6 )_trc * v ( h4 h6 p1 p5 )_v
C         i1 ( p9 h8 )_vtrbtrctra + = -1 * Sum ( h2 ) * tra ( p9 h2 )_tra * i2 ( h2 h8 )_vtrbtrc
C             i2 ( h2 h8 )_vtrbtrc + = 1 * Sum ( p5 ) * trc ( p5 h8 )_trc * i3 ( h2 p5 )_vtrb
C                 i3 ( h2 p5 )_vtrb + = 1 * Sum ( h4 p3 ) * trb ( p3 h4 )_trb * v ( h2 h4 p3 p5 )_v
C             i2 ( h2 h8 )_vtrctrb + = -1 * Sum ( p3 ) * trb ( p3 h8 )_trb * i3 ( h2 p3 )_vtrc
C                 i3 ( h2 p3 )_vtrc + = 1 * Sum ( h6 p5 ) * trc ( p5 h6 )_trc * v ( h2 h6 p3 p5 )_v
C         i1 ( p9 h8 )_vtratrbtrc + = 1 * Sum ( h6 ) * trc ( p9 h6 )_trc * i2 ( h6 h8 )_vtratrb
C             i2 ( h6 h8 )_vtratrb + = 1 * Sum ( p3 ) * trb ( p3 h8 )_trb * i3 ( h6 p3 )_vtra
C                 i3 ( h6 p3 )_vtra + = 1 * Sum ( h2 p1 ) * tra ( p1 h2 )_tra * v ( h2 h6 p1 p3 )_v
C             i2 ( h6 h8 )_vtrbtra + = -1 * Sum ( p1 ) * tra ( p1 h8 )_tra * i3 ( h6 p1 )_vtrb
C                 i3 ( h6 p1 )_vtrb + = 1 * Sum ( h4 p3 ) * trb ( p3 h4 )_trb * v ( h4 h6 p1 p3 )_v
C     i0 ( )_ytrbtratrcv + = -1 * Sum ( h7 p8 h10 h11 ) * i1 ( h7 p8 h10 h11 )_ytrbtratrc * v ( h10 h11 h7 p8 )_v
C         i1 ( h7 p8 h10 h11 )_ytrbtratrc + = 1 * Sum ( h6 ) * trc ( p8 h6 )_trc * i2 ( h6 h7 h10 h11 )_ytrbtra
C             i2 ( h6 h7 h10 h11 )_ytrbtra + = 1 * Sum ( p1 ) * tra ( p1 h10 )_tra * i3 ( h6 h7 h11 p1 )_ytrb
C                 i3 ( h6 h7 h11 p1 )_ytrb + = 1 * Sum ( p3 ) * trb ( p3 h11 )_trb * y ( h6 h7 p1 p3 )_y
C         i1 ( h7 p8 h10 h11 )_ytrctratrb + = 1 * Sum ( h4 ) * trb ( p8 h4 )_trb * i2 ( h4 h7 h10 h11 )_ytrctra
C             i2 ( h4 h7 h10 h11 )_ytrctra + = 1 * Sum ( p1 ) * tra ( p1 h10 )_tra * i3 ( h4 h7 h11 p1 )_ytrc
C                 i3 ( h4 h7 h11 p1 )_ytrc + = 1 * Sum ( p5 ) * trc ( p5 h11 )_trc * y ( h4 h7 p1 p5 )_y
C         i1 ( h7 p8 h10 h11 )_ytrctrbtra + = 1 * Sum ( h2 ) * tra ( p8 h2 )_tra * i2 ( h2 h7 h10 h11 )_ytrctrb
C             i2 ( h2 h7 h10 h11 )_ytrctrb + = 1 * Sum ( p3 ) * trb ( p3 h10 )_trb * i3 ( h2 h7 h11 p3 )_ytrc
C                 i3 ( h2 h7 h11 p3 )_ytrc + = 1 * Sum ( p5 ) * trc ( p5 h11 )_trc * y ( h2 h7 p3 p5 )_y
C     i0 ( )_vtrctrbtray + = -1 * Sum ( p12 p9 h10 h11 ) * y ( h10 h11 p9 p12 )_y * i1 ( p9 p12 h10 h11 )_vtrctrbtra
C         i1 ( p9 p12 h10 h11 )_vtrctrbtra + = 1 * Sum ( h2 ) * tra ( p12 h2 )_tra * i2 ( h2 p9 h10 h11 )_vtrctrb
C             i2 ( h2 p9 h10 h11 )_vtrctrb + = 1 * Sum ( p3 ) * trb ( p3 h10 )_trb * i3 ( h2 p9 h11 p3 )_vtrc
C                 i3 ( h2 p9 h11 p3 )_vtrc + = -1 * Sum ( p5 ) * trc ( p5 h11 )_trc * v ( h2 p9 p3 p5 )_v
C             i2 ( h2 p9 h10 h11 )_vtrctrb + = -1 * Sum ( h6 p4 ) * trb ( p4 p9 h6 h10 )_trb * i3 ( h2 h6 h11 p4 )_vtrc
C                 i3 ( h2 h6 h11 p4 )_vtrc + = 1 * Sum ( p7 ) * trc ( p7 h11 )_trc * v ( h2 h6 p4 p7 )_v
C             i2 ( h2 p9 h10 h11 )_vtrbtrc + = -1/4 * Sum ( h8 ) * trc ( p9 h8 )_trc * i3 ( h2 h8 h10 h11 )_vtrb
C                 i3 ( h2 h8 h10 h11 )_vtrb + = -1 * Sum ( p3 p4 ) * trb ( p3 p4 h10 h11 )_trb * v ( h2 h8 p3 p4 )_v
C             i2 ( h2 p9 h10 h11 )_vtrctrb + = -1/2 * Sum ( p4 ) * trb ( p4 p9 h10 h11 )_trb * i3 ( h2 p4 )_vtrc
C                 i3 ( h2 p4 )_vtrc + = 1 * Sum ( h8 p7 ) * trc ( p7 h8 )_trc * v ( h2 h8 p4 p7 )_v
C             i2 ( h2 p9 h10 h11 )_vtrbtrc + = -1 * Sum ( h8 p6 ) * trc ( p6 p9 h8 h11 )_trc * i3 ( h2 h8 h10 p6 )_vtrb
C                 i3 ( h2 h8 h10 p6 )_vtrb + = 1 * Sum ( p3 ) * trb ( p3 h10 )_trb * v ( h2 h8 p3 p6 )_v
C             i2 ( h2 p9 h10 h11 )_vtrctrb + = -1/4 * Sum ( h4 ) * trb ( p9 h4 )_trb * i3 ( h2 h4 h10 h11 )_vtrc
C                 i3 ( h2 h4 h10 h11 )_vtrc + = -1 * Sum ( p5 p6 ) * trc ( p5 p6 h10 h11 )_trc * v ( h2 h4 p5 p6 )_v
C             i2 ( h2 p9 h10 h11 )_vtrbtrc + = 1/2 * Sum ( p6 ) * trc ( p6 p9 h10 h11 )_trc * i3 ( h2 p6 )_vtrb
C                 i3 ( h2 p6 )_vtrb + = 1 * Sum ( h4 p3 ) * trb ( p3 h4 )_trb * v ( h2 h4 p3 p6 )_v
C             i2 ( h2 p9 h10 h11 )_vtrctrbt + = 1/2 * Sum ( h4 ) * t ( p9 h4 )_t * i3 ( h2 h4 h10 h11 )_vtrctrb
C                 i3 ( h2 h4 h10 h11 )_vtrctrb + = 1 * Sum ( p5 ) * trb ( p5 h10 )_trb * i4 ( h2 h4 h11 p5 )_vtrc
C                     i4 ( h2 h4 h11 p5 )_vtrc + = 1 * Sum ( p7 ) * trc ( p7 h11 )_trc * v ( h2 h4 p5 p7 )_v
C         i1 ( p9 p12 h10 h11 )_vtrctratrb + = 1 * Sum ( h4 ) * trb ( p12 h4 )_trb * i2 ( h4 p9 h10 h11 )_vtrctra
C             i2 ( h4 p9 h10 h11 )_vtrctra + = 1 * Sum ( p1 ) * tra ( p1 h10 )_tra * i3 ( h4 p9 h11 p1 )_vtrc
C                 i3 ( h4 p9 h11 p1 )_vtrc + = -1 * Sum ( p5 ) * trc ( p5 h11 )_trc * v ( h4 p9 p1 p5 )_v
C         i1 ( p9 p12 h10 h11 )_vtrbtratrc + = 1 * Sum ( h6 ) * trc ( p12 h6 )_trc * i2 ( h6 p9 h10 h11 )_vtrbtra
C             i2 ( h6 p9 h10 h11 )_vtrbtra + = 1 * Sum ( p1 ) * tra ( p1 h10 )_tra * i3 ( h6 p9 h11 p1 )_vtrb
C                 i3 ( h6 p9 h11 p1 )_vtrb + = -1 * Sum ( p3 ) * trb ( p3 h11 )_trb * v ( h6 p9 p1 p3 )_v
C         i1 ( p9 p12 h10 h11 )_vtrbtratrc + = -1/2 * Sum ( h8 ) * trc ( p9 p12 h8 h11 )_trc * i2 ( h8 h10 )_vtrbtra
C             i2 ( h8 h10 )_vtrbtra + = 1 * Sum ( p1 ) * tra ( p1 h10 )_tra * i3 ( h8 p1 )_vtrb
C                 i3 ( h8 p1 )_vtrb + = 1 * Sum ( h4 p3 ) * trb ( p3 h4 )_trb * v ( h4 h8 p1 p3 )_v
C         i1 ( p9 p12 h10 h11 )_vtrctrbtra + = 1/4 * Sum ( h3 h4 ) * tra ( p9 p12 h3 h4 )_tra * i2 ( h3 h4 h10 h11 )_vtrctrb
C             i2 ( h3 h4 h10 h11 )_vtrctrb + = 1 * Sum ( p5 ) * trb ( p5 h10 )_trb * i3 ( h3 h4 h11 p5 )_vtrc
C                 i3 ( h3 h4 h11 p5 )_vtrc + = -1 * Sum ( p7 ) * trc ( p7 h11 )_trc * v ( h3 h4 p5 p7 )_v
C         i1 ( p9 p12 h10 h11 )_vtrbtratrc + = -1 * Sum ( h8 ) * trc ( p9 h8 )_trc * i2 ( h8 p12 h10 h11 )_vtrbtra
C             i2 ( h8 p12 h10 h11 )_vtrbtra + = 1 * Sum ( h4 p2 ) * tra ( p2 p12 h4 h10 )_tra * i3 ( h4 h8 h11 p2 )_vtrb
C                 i3 ( h4 h8 h11 p2 )_vtrb + = 1 * Sum ( p5 ) * trb ( p5 h11 )_trb * v ( h4 h8 p2 p5 )_v
C             i2 ( h8 p12 h10 h11 )_vtrbtra + = 1/2 * Sum ( p2 ) * tra ( p2 p12 h10 h11 )_tra * i3 ( h8 p2 )_vtrb
C                 i3 ( h8 p2 )_vtrb + = 1 * Sum ( h6 p5 ) * trb ( p5 h6 )_trb * v ( h6 h8 p2 p5 )_v
C         i1 ( p9 p12 h10 h11 )_vtrctrbtra + = -1/2 * Sum ( h4 ) * tra ( p9 p12 h4 h10 )_tra * i2 ( h4 h11 )_vtrctrb
C             i2 ( h4 h11 )_vtrctrb + = 1 * Sum ( p5 ) * trb ( p5 h11 )_trb * i3 ( h4 p5 )_vtrc
C                 i3 ( h4 p5 )_vtrc + = 1 * Sum ( h8 p7 ) * trc ( p7 h8 )_trc * v ( h4 h8 p5 p7 )_v
C             i2 ( h4 h11 )_vtrbtrc + = -1 * Sum ( p7 ) * trc ( p7 h11 )_trc * i3 ( h4 p7 )_vtrb
C                 i3 ( h4 p7 )_vtrb + = 1 * Sum ( h6 p5 ) * trb ( p5 h6 )_trb * v ( h4 h6 p5 p7 )_v
C         i1 ( p9 p12 h10 h11 )_vtrctrbtrat + = 1/2 * Sum ( h2 ) * t ( p12 h2 )_t * i2 ( h2 p9 h10 h11 )_vtrctrbtra
C             i2 ( h2 p9 h10 h11 )_vtrctrbtra + = 1 * Sum ( h4 ) * tra ( p9 h4 )_tra * i3 ( h2 h4 h10 h11 )_vtrctrb
C     i0 ( )_ytrbtrctrav + = -1/4 * Sum ( p11 p12 h10 h13 ) * i1 ( p11 p12 h10 h13 )_ytrbtrctra * v ( h10 h13 p11 p12 )_v
C         i1 ( p11 p12 h10 h13 )_ytrbtrctra + = 1 * Sum ( h2 ) * tra ( p11 h2 )_tra * i2 ( h2 p12 h10 h13 )_ytrbtrc
C             i2 ( h2 p12 h10 h13 )_ytrbtrc + = 1 * Sum ( h8 ) * trc ( p12 h8 )_trc * i3 ( h2 h8 h10 h13 )_ytrb
C                 i3 ( h2 h8 h10 h13 )_ytrb + = -1 * Sum ( p3 p4 ) * trb ( p3 p4 h10 h13 )_trb * y ( h2 h8 p3 p4 )_y
C                 i3 ( h2 h8 h10 h13 )_ytrbt + = -4 * Sum ( p3 ) * t ( p3 h10 )_t * i4 ( h2 h8 h13 p3 )_ytrb
C                     i4 ( h2 h8 h13 p3 )_ytrb + = 1 * Sum ( p5 ) * trb ( p5 h13 )_trb * y ( h2 h8 p3 p5 )_y
C             i2 ( h2 p12 h10 h13 )_ytrctrb + = 4 * Sum ( h5 p3 ) * trb ( p3 p12 h5 h10 )_trb * i3 ( h2 h5 h13 p3 )_ytrc
C                 i3 ( h2 h5 h13 p3 )_ytrc + = 1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h2 h5 p3 p7 )_y
C             i2 ( h2 p12 h10 h13 )_ytrctrb + = 1 * Sum ( h1 ) * trb ( p12 h1 )_trb * i3 ( h1 h2 h10 h13 )_ytrc
C                 i3 ( h1 h2 h10 h13 )_ytrc + = 1 * Sum ( p5 p6 ) * trc ( p5 p6 h10 h13 )_trc * y ( h1 h2 p5 p6 )_y
C                 i3 ( h1 h2 h10 h13 )_ytrct + = -4 * Sum ( p3 ) * t ( p3 h10 )_t * i4 ( h1 h2 h13 p3 )_ytrc
C                     i4 ( h1 h2 h13 p3 )_ytrc + = -1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h1 h2 p3 p7 )_y
C             i2 ( h2 p12 h10 h13 )_ytrbtrc + = 4 * Sum ( h7 p5 ) * trc ( p5 p12 h7 h13 )_trc * i3 ( h2 h7 h10 p5 )_ytrb
C                 i3 ( h2 h7 h10 p5 )_ytrb + = 1 * Sum ( p3 ) * trb ( p3 h10 )_trb * y ( h2 h7 p3 p5 )_y
C             i2 ( h2 p12 h10 h13 )_ytrctrbt + = -2 * Sum ( h4 ) * t ( p12 h4 )_t * i3 ( h2 h4 h10 h13 )_ytrctrb
C                 i3 ( h2 h4 h10 h13 )_ytrctrb + = 1 * Sum ( p5 ) * trb ( p5 h10 )_trb * i4 ( h2 h4 h13 p5 )_ytrc
C                     i4 ( h2 h4 h13 p5 )_ytrc + = 1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h2 h4 p5 p7 )_y
C         i1 ( p11 p12 h10 h13 )_ytrbtratrc + = 2 * trc ( p12 h13 )_trc * i2 ( p11 h10 )_ytrbtra
C             i2 ( p11 h10 )_ytrbtra + = 1 * Sum ( h2 ) * tra ( p11 h2 )_tra * i3 ( h2 h10 )_ytrb
C                 i3 ( h2 h10 )_ytrb + = -1 * Sum ( h5 p3 p4 ) * trb ( p3 p4 h5 h10 )_trb * y ( h2 h5 p3 p4 )_y
C             i2 ( p11 h10 )_ytrbtra + = -1 * Sum ( h3 h4 p1 ) * tra ( p1 p11 h3 h4 )_tra * i3 ( h3 h4 h10 p1 )_ytrb
C                 i3 ( h3 h4 h10 p1 )_ytrb + = -1 * Sum ( p5 ) * trb ( p5 h10 )_trb * y ( h3 h4 p1 p5 )_y
C         i1 ( p11 p12 h10 h13 )_ytrbtrctra + = -2 * tra ( p11 h10 )_tra * i2 ( p12 h13 )_ytrbtrc
C             i2 ( p12 h13 )_ytrbtrc + = 1 * Sum ( h8 ) * trc ( p12 h8 )_trc * i3 ( h8 h13 )_ytrb
C                 i3 ( h8 h13 )_ytrb + = -1 * Sum ( h5 p3 p4 ) * trb ( p3 p4 h5 h13 )_trb * y ( h5 h8 p3 p4 )_y
C             i2 ( p12 h13 )_ytrctrb + = 1 * Sum ( h5 h6 p3 ) * trb ( p3 p12 h5 h6 )_trb * i3 ( h5 h6 h13 p3 )_ytrc
C                 i3 ( h5 h6 h13 p3 )_ytrc + = -1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h5 h6 p3 p7 )_y
C             i2 ( p12 h13 )_ytrctrb + = -1 * Sum ( h4 ) * trb ( p12 h4 )_trb * i3 ( h4 h13 )_ytrc
C                 i3 ( h4 h13 )_ytrc + = -1 * Sum ( h7 p5 p6 ) * trc ( p5 p6 h7 h13 )_trc * y ( h4 h7 p5 p6 )_y
C             i2 ( p12 h13 )_ytrbtrc + = -1 * Sum ( h7 h8 p5 ) * trc ( p5 p12 h7 h8 )_trc * i3 ( h7 h8 h13 p5 )_ytrb
C                 i3 ( h7 h8 h13 p5 )_ytrb + = -1 * Sum ( p3 ) * trb ( p3 h13 )_trb * y ( h7 h8 p3 p5 )_y
C         i1 ( p11 p12 h10 h13 )_ytrbtratrc + = 4 * Sum ( h8 ) * trc ( p12 h8 )_trc * i2 ( h8 p11 h10 h13 )_ytrbtra
C             i2 ( h8 p11 h10 h13 )_ytrbtra + = 1 * Sum ( h3 p1 ) * tra ( p1 p11 h3 h10 )_tra * i3 ( h3 h8 h13 p1 )_ytrb
C                 i3 ( h3 h8 h13 p1 )_ytrb + = 1 * Sum ( p5 ) * trb ( p5 h13 )_trb * y ( h3 h8 p1 p5 )_y
C         i1 ( p11 p12 h10 h13 )_ytrctrbtra + = 1 * Sum ( h3 h4 ) * tra ( p11 p12 h3 h4 )_tra * i2 ( h3 h4 h10 h13 )_ytrctrb
C             i2 ( h3 h4 h10 h13 )_ytrctrb + = 1 * Sum ( p5 ) * trb ( p5 h10 )_trb * i3 ( h3 h4 h13 p5 )_ytrc
C                 i3 ( h3 h4 h13 p5 )_ytrc + = -1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h3 h4 p5 p7 )_y
C         i1 ( p11 p12 h10 h13 )_ytrbtratrct + = -4 * Sum ( h2 ) * t ( p11 h2 )_t * i2 ( h2 p12 h10 h13 )_ytrbtratrc
C             i2 ( h2 p12 h10 h13 )_ytrbtratrc + = 1 * Sum ( h8 ) * trc ( p12 h8 )_trc * i3 ( h2 h8 h10 h13 )_ytrbtra
C                 i3 ( h2 h8 h10 h13 )_ytrbtra + = 1 * Sum ( p3 ) * tra ( p3 h10 )_tra * i4 ( h2 h8 h13 p3 )_ytrb
C             i2 ( h2 p12 h10 h13 )_ytrctratrb + = 1 * Sum ( h6 ) * trb ( p12 h6 )_trb * i3 ( h2 h6 h10 h13 )_ytrctra
C                 i3 ( h2 h6 h10 h13 )_ytrctra + = 1 * Sum ( p3 ) * tra ( p3 h10 )_tra * i4 ( h2 h6 h13 p3 )_ytrc
C                     i4 ( h2 h6 h13 p3 )_ytrc + = 1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h2 h6 p3 p7 )_y
C             i2 ( h2 p12 h10 h13 )_ytrctrbtra + = 1/2 * Sum ( h4 ) * tra ( p12 h4 )_tra * i3 ( h2 h4 h10 h13 )_ytrctrb
      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_y1
      INTEGER k_y1_offset
      INTEGER d_i1
      INTEGER k_i1_offset
      INTEGER d_v2
      INTEGER k_v2_offset
      INTEGER d_y2
      INTEGER k_y2_offset
      INTEGER l_i1_offset
      INTEGER d_trb1
      INTEGER k_trb1_offset
      INTEGER d_i2
      INTEGER k_i2_offset
      INTEGER size_i1
      INTEGER d_tra1
      INTEGER k_tra1_offset
      INTEGER d_trc1
      INTEGER k_trc1_offset
      INTEGER l_i2_offset
      INTEGER d_i3
      INTEGER k_i3_offset
      INTEGER size_i2
      INTEGER l_i3_offset
      INTEGER size_i3
      INTEGER d_trc2
      INTEGER k_trc2_offset
      INTEGER d_tra2
      INTEGER k_tra2_offset
      INTEGER d_t1
      INTEGER k_t1_offset
      INTEGER d_trb2
      INTEGER k_trb2_offset
      INTEGER d_i4
      INTEGER k_i4_offset
      INTEGER l_i4_offset
      INTEGER size_i4
      CHARACTER*255 filename
      CALL OFFSET_beta_1_1_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('beta_1_1_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL OFFSET_beta_1_1_1_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_1_1_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_1_1_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_1_1_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_1_1_1_1(d_tra1,k_tra1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_1_1_1(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_1_1_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_1_1_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_1_1_2_1(d_trc1,k_trc1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_1_1_2(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_1_1(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_1_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_1_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_1_2_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_1_2_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_1_2_1_1(d_trb1,k_trb1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_1_2_1(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_1_2_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_1_2_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_1_2_2_1(d_trc1,k_trc1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_1_2_2(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_1_2(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_1_3_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_1_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_1_3_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_1_3_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_1_3_1_1(d_tra1,k_tra1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_1_3_1(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_1_3_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_1_3_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_1_3_2_1(d_trb1,k_trb1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_1_3_2(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_1_3(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL beta_1_1(d_y1,k_y1_offset,d_i1,k_i1_offset,d_i0,k_i0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_2_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('beta_1_2_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL OFFSET_beta_1_2_1_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_2_1_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_2_1_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_2_1_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_2_1_1_1(d_trb1,k_trb1_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_2_1_1(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_2_1(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_2_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_2_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_2_2_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_2_2_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_2_2_1_1(d_trc1,k_trc1_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_2_2_1(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_2_2(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_2_3_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_2_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_2_3_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_2_3_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_2_3_1_1(d_trc1,k_trc1_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_2_3_1(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_2_3(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL beta_1_2(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('beta_1_3_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL OFFSET_beta_1_3_1_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_3_1_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_3_1_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_1_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_1_1_1(d_trc1,k_trc1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_1_1(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_1_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_1_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_1_2_1(d_trc1,k_trc1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_1_2(d_trb2,k_trb2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_1_3_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_1_3_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_1_3_1(d_trb2,k_trb2_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_1_3(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_1_4_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_1_4_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_1_4_1(d_trc1,k_trc1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_1_4(d_trb2,k_trb2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_1_5_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_1_5_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_1_5_1(d_trb1,k_trb1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_1_5(d_trc2,k_trc2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_1_6_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_1_6_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_1_6_1(d_trc2,k_trc2_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_1_6(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_1_7_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_1_7_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_1_7_1(d_trb1,k_trb1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_1_7(d_trc2,k_trc2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_1_8_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_1_8_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL OFFSET_beta_1_3_1_8_1_1(l_i4_offset,k_i4_offset,size_i4)
      CALL TCE_FILENAME('beta_1_3_1_8_1_1_i4',filename)
      CALL CREATEFILE(filename,d_i4,size_i4)
      CALL beta_1_3_1_8_1_1(d_trc1,k_trc1_offset,d_v2,k_v2_offset,d_i4,k
     &_i4_offset)
      CALL RECONCILEFILE(d_i4,size_i4)
      CALL beta_1_3_1_8_1(d_trb1,k_trb1_offset,d_i4,k_i4_offset,d_i3,k_i
     &3_offset)
      CALL DELETEFILE(d_i4)
      IF (.not.MA_POP_STACK(l_i4_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_1_8(d_t1,k_t1_offset,d_i3,k_i3_offset,d_i2,k_i2_offs
     &et)
      CALL DELETEFILE(d_i3)
      IF (.not.MA_POP_STACK(l_i3_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_3_1(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_3_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_3_2_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_2_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_2_1_1(d_trc1,k_trc1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_2_1(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_3_2(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_3_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_3_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_3_3_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_3_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_3_1_1(d_trb1,k_trb1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_3_1(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_3_3(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_4_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_3_4_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_3_4_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_4_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_4_1_1(d_trb1,k_trb1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_4_1(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_3_4(d_trc2,k_trc2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_5_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_3_5_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_3_5_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_5_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_5_1_1(d_trc1,k_trc1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_5_1(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_3_5(d_tra2,k_tra2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_6_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_3_6_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_3_6_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_6_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_6_1_1(d_trb1,k_trb1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_6_1(d_tra2,k_tra2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_6_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_6_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_6_2_1(d_trb1,k_trb1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_6_2(d_tra2,k_tra2_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_3_6(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_7_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_3_7_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_3_7_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_7_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_7_1_1(d_trc1,k_trc1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_7_1(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_7_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_7_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_3_7_2_1(d_trb1,k_trb1_offset,d_v2,k_v2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_7_2(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_3_7(d_tra2,k_tra2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_3_8_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_3_8_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_3_8_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_3_8_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL OFFSET_beta_1_3_8_1_1_1(l_i4_offset,k_i4_offset,size_i4)
      CALL TCE_FILENAME('beta_1_3_8_1_1_1_i4',filename)
      CALL CREATEFILE(filename,d_i4,size_i4)
      CALL beta_1_3_8_1_1_1(d_trc1,k_trc1_offset,d_v2,k_v2_offset,d_i4,k
     &_i4_offset)
      CALL RECONCILEFILE(d_i4,size_i4)
      CALL beta_1_3_8_1_1(d_trb1,k_trb1_offset,d_i4,k_i4_offset,d_i3,k_i
     &3_offset)
      CALL DELETEFILE(d_i4)
      IF (.not.MA_POP_STACK(l_i4_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_3_8_1(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_3_8(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_offset
     &)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL beta_1_3(d_y2,k_y2_offset,d_i1,k_i1_offset,d_i0,k_i0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('beta_1_4_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL OFFSET_beta_1_4_1_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_4_1_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_4_1_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_1_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_1_1_1(d_trb2,k_trb2_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL OFFSET_beta_1_4_1_1_2_1(l_i4_offset,k_i4_offset,size_i4)
      CALL TCE_FILENAME('beta_1_4_1_1_2_1_i4',filename)
      CALL CREATEFILE(filename,d_i4,size_i4)
      CALL beta_1_4_1_1_2_1(d_trb1,k_trb1_offset,d_y2,k_y2_offset,d_i4,k
     &_i4_offset)
      CALL RECONCILEFILE(d_i4,size_i4)
      CALL beta_1_4_1_1_2(d_t1,k_t1_offset,d_i4,k_i4_offset,d_i3,k_i3_of
     &fset)
      CALL DELETEFILE(d_i4)
      IF (.not.MA_POP_STACK(l_i4_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_1_1(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_1_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_1_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_1_2_1(d_trc1,k_trc1_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_1_2(d_trb2,k_trb2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_1_3_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_1_3_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_1_3_1(d_trc2,k_trc2_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL OFFSET_beta_1_4_1_3_2_1(l_i4_offset,k_i4_offset,size_i4)
      CALL TCE_FILENAME('beta_1_4_1_3_2_1_i4',filename)
      CALL CREATEFILE(filename,d_i4,size_i4)
      CALL beta_1_4_1_3_2_1(d_trc1,k_trc1_offset,d_y2,k_y2_offset,d_i4,k
     &_i4_offset)
      CALL RECONCILEFILE(d_i4,size_i4)
      CALL beta_1_4_1_3_2(d_t1,k_t1_offset,d_i4,k_i4_offset,d_i3,k_i3_of
     &fset)
      CALL DELETEFILE(d_i4)
      IF (.not.MA_POP_STACK(l_i4_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_1_3(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_1_4_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_1_4_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_1_4_1(d_trb1,k_trb1_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_1_4(d_trc2,k_trc2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_1_5_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_1_5_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL OFFSET_beta_1_4_1_5_1_1(l_i4_offset,k_i4_offset,size_i4)
      CALL TCE_FILENAME('beta_1_4_1_5_1_1_i4',filename)
      CALL CREATEFILE(filename,d_i4,size_i4)
      CALL beta_1_4_1_5_1_1(d_trc1,k_trc1_offset,d_y2,k_y2_offset,d_i4,k
     &_i4_offset)
      CALL RECONCILEFILE(d_i4,size_i4)
      CALL beta_1_4_1_5_1(d_trb1,k_trb1_offset,d_i4,k_i4_offset,d_i3,k_i
     &3_offset)
      CALL DELETEFILE(d_i4)
      IF (.not.MA_POP_STACK(l_i4_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_1_5(d_t1,k_t1_offset,d_i3,k_i3_offset,d_i2,k_i2_offs
     &et)
      CALL DELETEFILE(d_i3)
      IF (.not.MA_POP_STACK(l_i3_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_4_1(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_4_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_4_2_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_2_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_2_1_1(d_trb2,k_trb2_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_2_1(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_2_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_2_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_2_2_1(d_trb1,k_trb1_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_2_2(d_tra2,k_tra2_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_4_2(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_3_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_4_3_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_4_3_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_3_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_3_1_1(d_trb2,k_trb2_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_3_1(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_3_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_3_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_3_2_1(d_trc1,k_trc1_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_3_2(d_trb2,k_trb2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_3_3_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_3_3_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_3_3_1(d_trc2,k_trc2_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_3_3(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_3_4_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_3_4_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_3_4_1(d_trb1,k_trb1_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_3_4(d_trc2,k_trc2_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_4_3(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_4_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_4_4_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_4_4_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_4_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_4_1_1(d_trb1,k_trb1_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_4_1(d_tra2,k_tra2_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_4_4(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_5_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_4_5_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_4_5_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_5_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL beta_1_4_5_1_1(d_trc1,k_trc1_offset,d_y2,k_y2_offset,d_i3,k_i
     &3_offset)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_5_1(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_4_5(d_tra2,k_tra2_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_6_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('beta_1_4_6_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL OFFSET_beta_1_4_6_1_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_6_1_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL OFFSET_beta_1_4_6_1_1_1(l_i4_offset,k_i4_offset,size_i4)
      CALL TCE_FILENAME('beta_1_4_6_1_1_1_i4',filename)
      CALL CREATEFILE(filename,d_i4,size_i4)
      CALL beta_1_4_6_1_1_1(d_trb1,k_trb1_offset,d_y2,k_y2_offset,d_i4,k
     &_i4_offset)
      CALL RECONCILEFILE(d_i4,size_i4)
      CALL beta_1_4_6_1_1(d_tra1,k_tra1_offset,d_i4,k_i4_offset,d_i3,k_i
     &3_offset)
      CALL DELETEFILE(d_i4)
      IF (.not.MA_POP_STACK(l_i4_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_6_1(d_trc1,k_trc1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_6_2_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_6_2_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL OFFSET_beta_1_4_6_2_1_1(l_i4_offset,k_i4_offset,size_i4)
      CALL TCE_FILENAME('beta_1_4_6_2_1_1_i4',filename)
      CALL CREATEFILE(filename,d_i4,size_i4)
      CALL beta_1_4_6_2_1_1(d_trc1,k_trc1_offset,d_y2,k_y2_offset,d_i4,k
     &_i4_offset)
      CALL RECONCILEFILE(d_i4,size_i4)
      CALL beta_1_4_6_2_1(d_tra1,k_tra1_offset,d_i4,k_i4_offset,d_i3,k_i
     &3_offset)
      CALL DELETEFILE(d_i4)
      IF (.not.MA_POP_STACK(l_i4_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_6_2(d_trb1,k_trb1_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('beta_1',-1,MA_ER
     &R)
      CALL OFFSET_beta_1_4_6_3_1(l_i3_offset,k_i3_offset,size_i3)
      CALL TCE_FILENAME('beta_1_4_6_3_1_i3',filename)
      CALL CREATEFILE(filename,d_i3,size_i3)
      CALL OFFSET_beta_1_4_6_3_1_1(l_i4_offset,k_i4_offset,size_i4)
      CALL TCE_FILENAME('beta_1_4_6_3_1_1_i4',filename)
      CALL CREATEFILE(filename,d_i4,size_i4)
      CALL beta_1_4_6_3_1_1(d_trc1,k_trc1_offset,d_y2,k_y2_offset,d_i4,k
     &_i4_offset)
      CALL RECONCILEFILE(d_i4,size_i4)
      CALL beta_1_4_6_3_1(d_trb1,k_trb1_offset,d_i4,k_i4_offset,d_i3,k_i
     &3_offset)
      CALL DELETEFILE(d_i4)
      IF (.not.MA_POP_STACK(l_i4_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i3,size_i3)
      CALL beta_1_4_6_3(d_tra1,k_tra1_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('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL beta_1_4_6(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1_offset
     &)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL beta_1_4(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('beta_1',-1,MA_ER
     &R)
      RETURN
      END
      SUBROUTINE beta_1_1_1_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h4 p5 )_vtra + = 1 * Sum ( h2 p1 ) * tra ( p1 h2 )_tra * v ( h2 h4 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 h4b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p1b
      INTEGER h2b
      INTEGER p1b_1
      INTEGER h2b_1
      INTEGER h4b_2
      INTEGER h2b_2
      INTEGER p5b_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 h4b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p5b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p5b-1)) .eq. ieor(irrep_
     &v,irrep_tra)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_1_1_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p1b = noab+1,noab+nvab
      DO h2b = 1,noab
      IF (int_mb(k_spin+p1b-1) .eq. int_mb(k_spin+h2b-1)) THEN
      IF (ieor(int_mb(k_sym+p1b-1),int_mb(k_sym+h2b-1)) .eq. irrep_tra) 
     &THEN
      CALL TCE_RESTRICTED_2(p1b,h2b,p1b_1,h2b_1)
      CALL TCE_RESTRICTED_4(h4b,h2b,p5b,p1b,h4b_2,h2b_2,p5b_2,p1b_2)
      dim_common = int_mb(k_range+p1b-1) * int_mb(k_range+h2b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = 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('beta_1_1_1_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_1_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h2b_1
     & - 1 + noab * (p1b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h2b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_1_1_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_1_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_1_1_1',5,MA_ERR)
      IF ((h2b .le. h4b) .and. (p1b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (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) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p1b_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+p1b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h2b .le. h4b) .and. (p5b .lt. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (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) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p1b_2,p5b_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+p5b-1),int_mb(k_range+p1b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h4b .lt. h2b) .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) * (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),
     &(p5b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p5b_2,p1b_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+p1b-1),int_mb(k_range+p5b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h4b .lt. h2b) .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) * (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),
     &(p1b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p1b_2,p5b_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+p5b-1),int_mb(k_range+p1b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_1_1_1_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('beta_1_1_1_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_1_1_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('
     &beta_1_1_1_1_1',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+h4b-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 * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_1_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_1_1_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 beta_1_1_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h8 )_vtratrc + = 1 * Sum ( p5 ) * trc ( p5 h8 )_trc * i3 ( h4 p5 )_vtra
      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 h8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h8b_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 h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h8b-1)) .eq. ieor(irrep_
     &v,ieor(irrep_tra,irrep_trc))) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_1_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+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h8b-1)) .eq. irrep_trc) 
     &THEN
      CALL TCE_RESTRICTED_2(p5b,h8b,p5b_1,h8b_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+h8b-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('beta_1_1_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_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+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_1_1_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_1_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('beta_1_1_1_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('beta_1_1_1_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_1_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('
     &beta_1_1_1_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+h8b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_1_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_1_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 beta_1_1_1_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h4 p1 )_vtrc + = 1 * Sum ( h6 p5 ) * trc ( p5 h6 )_trc * v ( h4 h6 p1 p5 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h6b
      INTEGER p5b_1
      INTEGER h6b_1
      INTEGER h4b_2
      INTEGER h6b_2
      INTEGER p1b_2
      INTEGER p5b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL 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_trc)) 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('beta_1_1_1_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO h6b = 1,noab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h6b-1)) .eq. irrep_trc) 
     &THEN
      CALL TCE_RESTRICTED_2(p5b,h6b,p5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h4b,h6b,p1b,p5b,h4b_2,h6b_2,p1b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+h6b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('beta_1_1_1_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_1_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_1_1_2_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_1_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_1_2_1',5,MA_ERR)
      IF ((h6b .lt. h4b) .and. (p5b .lt. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p1b_2,p5b_2,h4b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p5b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h6b .lt. h4b) .and. (p1b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p5b_2,p1b_2,h4b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p1b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h4b .le. h6b) .and. (p5b .lt. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p1b_2,p5b_2,h6b_2,h4b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p5b-1),int_mb(k_range+p1b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h4b .le. h6b) .and. (p1b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p5b_2,p1b_2,h6b_2,h4b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_mb(k_range+p5b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_1_1_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('beta_1_1_1_2_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_1_2_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('
     &beta_1_1_1_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('beta_1_1_1_2_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_1_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 beta_1_1_1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h8 )_vtrctra + = 1 * Sum ( p1 ) * tra ( p1 h8 )_tra * i3 ( h4 p1 )_vtrc
      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 h8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p1b
      INTEGER p1b_1
      INTEGER h8b_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 h4b = 1,noab
      DO h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h8b-1)) .eq. ieor(irrep_
     &v,ieor(irrep_trc,irrep_tra))) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_1_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p1b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p1b-1),int_mb(k_sym+h8b-1)) .eq. irrep_tra) 
     &THEN
      CALL TCE_RESTRICTED_2(p1b,h8b,p1b_1,h8b_1)
      CALL TCE_RESTRICTED_2(h4b,p1b,h4b_2,p1b_2)
      dim_common = int_mb(k_range+p1b-1)
      dima_sort = int_mb(k_range+h8b-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('beta_1_1_1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_1_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p1b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_1_1_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_1_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),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_1_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('beta_1_1_1_2',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_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('
     &beta_1_1_1_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+h8b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_1_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_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 beta_1_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h8 )_vtratrctrb + = 1 * Sum ( h4 ) * trb ( p9 h4 )_trb * i2 ( h4 h8 )_vtratrc
      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 h8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p9b_1
      INTEGER h4b_1
      INTEGER h4b_2
      INTEGER h8b_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 h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      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. ieor(irrep_
     &v,ieor(irrep_tra,ieor(irrep_trc,irrep_trb)))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_1',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_trb) 
     &THEN
      CALL TCE_RESTRICTED_2(p9b,h4b,p9b_1,h4b_1)
      CALL TCE_RESTRICTED_2(h4b,h8b,h4b_2,h8b_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+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('beta_1_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_1',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('beta_1_1_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h8b_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+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_1_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('beta_1_1_1',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_1',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_1_1',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+p9b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (p9b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_1',11,MA_E
     &RR)
      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 beta_1_1_2_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p5 )_vtrb + = 1 * Sum ( h4 p3 ) * trb ( p3 h4 )_trb * v ( h2 h4 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 p5b
      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 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 h2b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p5b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+p5b-1)) .eq. ieor(irrep_
     &v,irrep_trb)) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_2_1_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_trb) 
     &THEN
      CALL TCE_RESTRICTED_2(p3b,h4b,p3b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p5b,p3b,h2b_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+h2b-1) * int_mb(k_range+p5b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('beta_1_1_2_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_2_1_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('beta_1_1_2_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_2_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_2_1_1',5,MA_ERR)
      IF ((h4b .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) * (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) * (h2b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p5b_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+p5b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h4b .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) * (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) * (h2b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p3b_2,p5b_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+p5b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF ((h2b .le. h4b) .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) * (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),
     &(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_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+p5b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h2b .le. h4b) .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) * (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) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p5b_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+p5b-1),int_mb(k_range+p3b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_1_2_1_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('beta_1_1_2_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_2_1_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('
     &beta_1_1_2_1_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h2b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p5b -
     & noab - 1 + nvab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_2_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_2_1_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 beta_1_1_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 )_vtrbtrc + = 1 * Sum ( p5 ) * trc ( p5 h8 )_trc * i3 ( h2 p5 )_vtrb
      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 dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER p5b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h8b-1)) .eq. ieor(irrep_
     &v,ieor(irrep_trb,irrep_trc))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_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+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h8b-1)) .eq. irrep_trc) 
     &THEN
      CALL TCE_RESTRICTED_2(p5b,h8b,p5b_1,h8b_1)
      CALL TCE_RESTRICTED_2(h2b,p5b,h2b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+h8b-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('beta_1_1_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_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+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_1_2_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_2_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 * (h2b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p5b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_1_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('beta_1_1_2_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_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('
     &beta_1_1_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+h8b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_2_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_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
c done till here 2/7/2014
      SUBROUTINE beta_1_1_2_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p3 )_vtrc + = 1 * Sum ( h6 p5 ) * trc ( p5 h6 )_trc * v ( h2 h6 p3 p5 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h6b
      INTEGER p5b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER p5b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL 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_trc)) 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('beta_1_1_2_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO h6b = 1,noab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h6b-1)) .eq. irrep_trc) 
     &THEN
      CALL TCE_RESTRICTED_2(p5b,h6b,p5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,p3b,p5b,h2b_2,h6b_2,p3b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+h6b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('beta_1_1_2_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_2_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (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('beta_1_1_2_2_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_2_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_2_2_1',5,MA_ERR)
      IF ((h6b .lt. h2b) .and. (p5b .lt. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p3b_2,p5b_2,h2b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h6b .lt. h2b) .and. (p3b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p5b_2,p3b_2,h2b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h6b) .and. (p5b .lt. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p5b_2,h6b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h2b .le. h6b) .and. (p3b .le. p5b)) THEN
      if(.not.intorb) then 
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p3b_2,h6b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_1_2_2_1',6,MA_ERR
     &)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_1_2_2_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_2_2_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('
     &beta_1_1_2_2_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('beta_1_1_2_2_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_2_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 beta_1_1_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 )_vtrctrb + = -1 * Sum ( p3 ) * trb ( p3 h8 )_trb * i3 ( h2 p3 )_vtrc
      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 dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h8b_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 h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),int_mb(k_sym+h8b-1)) .eq. ieor(irrep_
     &v,ieor(irrep_trc,irrep_trb))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      IF (int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h8b-1)) .eq. irrep_trb) 
     &THEN
      CALL TCE_RESTRICTED_2(p3b,h8b,p3b_1,h8b_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+h8b-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('beta_1_1_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_2_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('beta_1_1_2_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_2_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h2b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p3b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_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('beta_1_1_2_2',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_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('
     &beta_1_1_2_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h8b-1),1,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (h2b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_2_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_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 beta_1_1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h8 )_vtrbtrctra + = -1 * Sum ( h2 ) * tra ( p9 h2 )_tra * i2 ( h2 h8 )_vtrbtrc
      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 h8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h2b
      INTEGER p9b_1
      INTEGER h2b_1
      INTEGER h2b_2
      INTEGER h8b_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 h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      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. ieor(irrep_
     &v,ieor(irrep_trb,ieor(irrep_trc,irrep_tra)))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h2b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h2b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h2b-1)) .eq. irrep_tra) 
     &THEN
      CALL TCE_RESTRICTED_2(p9b,h2b,p9b_1,h2b_1)
      CALL TCE_RESTRICTED_2(h2b,h8b,h2b_2,h8b_2)
      dim_common = int_mb(k_range+h2b-1)
      dima_sort = int_mb(k_range+p9b-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('beta_1_1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h2b_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+h2b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_1_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h8b_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+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_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('beta_1_1_2',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_2',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_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+p9b-1),2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (p9b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_2',11,MA_E
     &RR)
      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 beta_1_1_3_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h6 p3 )_vtra + = 1 * Sum ( h2 p1 ) * tra ( p1 h2 )_tra * v ( h2 h6 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 h6b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p1b
      INTEGER h2b
      INTEGER p1b_1
      INTEGER h2b_1
      INTEGER h6b_2
      INTEGER h2b_2
      INTEGER p3b_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 h6b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+p3b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+p3b-1)) .eq. ieor(irrep_
     &v,irrep_tra)) THEN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_3_1_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p1b = noab+1,noab+nvab
      DO h2b = 1,noab
      IF (int_mb(k_spin+p1b-1) .eq. int_mb(k_spin+h2b-1)) THEN
      IF (ieor(int_mb(k_sym+p1b-1),int_mb(k_sym+h2b-1)) .eq. irrep_tra) 
     &THEN
      CALL TCE_RESTRICTED_2(p1b,h2b,p1b_1,h2b_1)
      CALL TCE_RESTRICTED_4(h6b,h2b,p3b,p1b,h6b_2,h2b_2,p3b_2,p1b_2)
      dim_common = int_mb(k_range+p1b-1) * int_mb(k_range+h2b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('beta_1_1_3_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_3_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h2b_1
     & - 1 + noab * (p1b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h2b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_1_3_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_3_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_3_1_1',5,MA_ERR)
      IF ((h2b .le. h6b) .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) * (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) * (p1b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p1b_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+p1b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h2b .le. h6b) .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) * (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),
     &(p1b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p1b_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+p1b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h6b .lt. h2b) .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) * (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) * (p1b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p3b_2,p1b_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+p1b-1),int_mb(k_range+p3b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h6b .lt. h2b) .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) * (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),
     &(p1b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p1b_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+p1b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_1_3_1_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('beta_1_1_3_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_3_1_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('
     &beta_1_1_3_1_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+h6b-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 * (h6b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_3_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_3_1_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 beta_1_1_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h8 )_vtratrb + = 1 * Sum ( p3 ) * trb ( p3 h8 )_trb * i3 ( h6 p3 )_vtra
      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 h8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h8b_1
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h6b = 1,noab
      DO h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+h8b-1)) .eq. ieor(irrep_
     &v,ieor(irrep_tra,irrep_trb))) THEN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_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+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h8b-1)) .eq. irrep_trb) 
     &THEN
      CALL TCE_RESTRICTED_2(p3b,h8b,p3b_1,h8b_1)
      CALL TCE_RESTRICTED_2(h6b,p3b,h6b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('beta_1_1_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_3_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p3b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_1_3_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_3_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h6b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p3b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_1_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('beta_1_1_3_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_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('
     &beta_1_1_3_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h8b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (h6b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_3_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_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 beta_1_1_3_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h6 p1 )_vtrb + = 1 * Sum ( h4 p3 ) * trb ( p3 h4 )_trb * v ( h4 h6 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 h6b
      INTEGER p1b
      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 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 h6b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_trb)) THEN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_3_2_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_trb) 
     &THEN
      CALL TCE_RESTRICTED_2(p3b,h4b,p3b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h6b,h4b,p1b,p3b,h6b_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+h6b-1) * int_mb(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('beta_1_1_3_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_3_2_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('beta_1_1_3_2_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_3_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_3_2_1',5,MA_ERR)
      IF ((h4b .le. h6b) .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) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p1b_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+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h4b .le. h6b) .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) * (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) * (p1b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p3b_2,p1b_2,h6b_2,h4b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p1b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF ((h6b .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) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p1b_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+p1b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h6b .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) * (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) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p3b_2,p1b_2,h4b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p1b-1),int_mb(k_range+p3b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_1_3_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('beta_1_1_3_2_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_3_2_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('
     &beta_1_1_3_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+h6b-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 * (h6b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_3_2_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_3_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 beta_1_1_3_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h8 )_vtrbtra + = -1 * Sum ( p1 ) * tra ( p1 h8 )_tra * i3 ( h6 p1 )_vtrb
      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 h8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p1b
      INTEGER p1b_1
      INTEGER h8b_1
      INTEGER h6b_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 h6b = 1,noab
      DO h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),int_mb(k_sym+h8b-1)) .eq. ieor(irrep_
     &v,ieor(irrep_trb,irrep_tra))) THEN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_3_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p1b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p1b-1),int_mb(k_sym+h8b-1)) .eq. irrep_tra) 
     &THEN
      CALL TCE_RESTRICTED_2(p1b,h8b,p1b_1,h8b_1)
      CALL TCE_RESTRICTED_2(h6b,p1b,h6b_2,p1b_2)
      dim_common = int_mb(k_range+p1b-1)
      dima_sort = int_mb(k_range+h8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('beta_1_1_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_3_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p1b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_1_3_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_3_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 * (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+p1b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_1_3_2',6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_1_3_2',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_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('
     &beta_1_1_3_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h8b-1),1,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (h6b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_3_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_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 beta_1_1_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h8 )_vtratrbtrc + = 1 * Sum ( h6 ) * trc ( p9 h6 )_trc * i2 ( h6 h8 )_vtratrb
      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 h8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h6b
      INTEGER p9b_1
      INTEGER h6b_1
      INTEGER h6b_2
      INTEGER h8b_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 h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+h8b-1
     &).ne.4)) THEN
      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. ieor(irrep_
     &v,ieor(irrep_tra,ieor(irrep_trb,irrep_trc)))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h6b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h6b-1)) .eq. irrep_trc) 
     &THEN
      CALL TCE_RESTRICTED_2(p9b,h6b,p9b_1,h6b_1)
      CALL TCE_RESTRICTED_2(h6b,h8b,h6b_2,h8b_2)
      dim_common = int_mb(k_range+h6b-1)
      dima_sort = int_mb(k_range+p9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+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('beta_1_1_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p9b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+h6b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_1_3',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1_3',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h8b_2
     & - 1 + noab * (h6b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_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('beta_1_1_3',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_1_3',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_1_3',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+p9b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (p9b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1_3',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1_3',11,MA_E
     &RR)
      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 beta_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( )_vtratrctrby + = -1 * Sum ( p9 h8 ) * y ( h8 p9 )_y * i1 ( p9 h8 )_vtratrctrb
      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 dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p9b
      INTEGER h8b_1
      INTEGER p9b_1
      INTEGER p9b_2
      INTEGER h8b_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)
      IF (next.eq.count) THEN
      IF (0 .eq. ieor(irrep_v,ieor(irrep_tra,ieor(irrep_trc,ieor(irrep_t
     &rb,irrep_y))))) THEN
      dimc = 1
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h8b = 1,noab
      DO p9b = noab+1,noab+nvab
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p9b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+p9b-1)) .eq. irrep_y) TH
     &EN
      CALL TCE_RESTRICTED_2(h8b,p9b,h8b_1,p9b_1)
      CALL TCE_RESTRICTED_2(p9b,h8b,p9b_2,h8b_2)
      dim_common = int_mb(k_range+h8b-1) * int_mb(k_range+p9b-1)
      dima_sort = 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('beta_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p9b_1
     & - noab - 1 + 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+p9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h8b_2
     & - 1 + noab * (p9b_2 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+h8b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_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('beta_1_1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_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('
     &beta_1_1',9,MA_ERR)
      CALL TCE_SORT_0(dbl_mb(k_c_sort),dbl_mb(k_c),-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),0)
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_1',11,MA_ERR
     &)
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE beta_1_2_1_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h6 h7 h11 p1 )_ytrb + = 1 * Sum ( p3 ) * trb ( p3 h11 )_trb * y ( h6 h7 p1 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 h6b
      INTEGER h7b
      INTEGER h11b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h11b_1
      INTEGER h6b_2
      INTEGER h7b_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 h6b = 1,noab
      DO h7b = h6b,noab
      DO h11b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      IF (int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_y,irrep_trb))
     & THEN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_2_1_1_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p3b,h11b,p3b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h6b,h7b,p1b,p3b,h6b_2,h7b_2,p1b_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+h6b-1) * int_mb(k_range+h7b-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('beta_1_2_1_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_2_1_1_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('beta_1_2_1_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_2_1_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_2_1_1_1',5,MA_ERR)
      IF ((p3b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_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+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p1b_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+p1b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_2_1_1_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('beta_1_2_1_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_2_1_1_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('
     &beta_1_2_1_1_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+h7b-1),int_mb(k_range+h6b-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),(p1b -
     & noab - 1 + nvab * (h11b - 1 + noab * (h7b - 1 + noab * (h6b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_2_1_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_2_1_1_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 beta_1_2_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h7 h10 h11 )_ytrbtra + = 1 * Sum ( p1 ) * tra ( p1 h10 )_tra * i3 ( h6 h7 h11 p1 )_ytrb
      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 h7b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p1b
      INTEGER p1b_1
      INTEGER h10b_1
      INTEGER h6b_2
      INTEGER h7b_2
      INTEGER h11b_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 h6b = 1,noab
      DO h7b = h6b,noab
      DO h10b = 1,noab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trb,irrep_tra))) THEN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+h7b-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('beta_1_2_1_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p1b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p1b-1),int_mb(k_sym+h10b-1)) .eq. irrep_tra)
     & THEN
      CALL TCE_RESTRICTED_2(p1b,h10b,p1b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h6b,h7b,h11b,p1b,h6b_2,h7b_2,h11b_2,p1b_2)
      dim_common = int_mb(k_range+p1b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1) * int_mb(k_range+h7b-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('beta_1_2_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_2_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (p1b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_2_1_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_2_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_2_1_1',5,MA_ERR)
      IF ((h11b .le. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (h11b_2 - 1 + noab * (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+h11b-1),int_mb(k_range+p1b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_2_1_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('beta_1_2_1_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_2_1_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('
     &beta_1_2_1_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+h7b-1),int_mb(k_range+h6b-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 * (h7b - 1 + noab * (h6b - 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+h7b-1),int_mb(k_range+h6b-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 * (h7b - 1 + noab * (h6b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_2_1_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_2_1_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 beta_1_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h7 p8 h10 h11 )_ytrbtratrc + = 1 * Sum ( h6 ) * trc ( p8 h6 )_trc * i2 ( h6 h7 h10 h11 )_ytrbtra
      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 h7b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h6b
      INTEGER p8b_1
      INTEGER h6b_1
      INTEGER h7b_2
      INTEGER h6b_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 p8b = noab+1,noab+nvab
      DO h7b = 1,noab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h7b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h7b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trb,ieor(irrep_tra,irrep_trc)))) THEN
      dimc = int_mb(k_range+h7b-1) * int_mb(k_range+p8b-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('beta_1_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h6b = 1,noab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+h6b-1)) .eq. irrep_trc) 
     &THEN
      CALL TCE_RESTRICTED_2(p8b,h6b,p8b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h7b,h6b,h10b,h11b,h7b_2,h6b_2,h10b_2,h11b_2)
      dim_common = int_mb(k_range+h6b-1)
      dima_sort = int_mb(k_range+p8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h7b-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('beta_1_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (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+h6b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_2_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_2_1',5,MA_ERR)
      IF ((h6b .le. h7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF ((h7b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (h6b_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+h6b-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_b)) CALL ERRQUIT('beta_1_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('beta_1_2_1',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_2_1',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_2_1',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+h7b-1),int_mb(k_range+p8b-
     &1),3,4,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p8b - noab - 1 + nvab * (h7b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_2_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_2_1',11,MA_E
     &RR)
      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 beta_1_2_2_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h4 h7 h11 p1 )_ytrc + = 1 * Sum ( p5 ) * trc ( p5 h11 )_trc * y ( h4 h7 p1 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 h7b
      INTEGER h11b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h11b_1
      INTEGER h4b_2
      INTEGER h7b_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 h4b = 1,noab
      DO h7b = h4b,noab
      DO h11b = 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+h7b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_y,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_2_2_1_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_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h11b,p5b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h4b,h7b,p1b,p5b,h4b_2,h7b_2,p1b_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+h4b-1) * int_mb(k_range+h7b-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('beta_1_2_2_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_2_2_1_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('beta_1_2_2_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_2_2_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_2_2_1_1',5,MA_ERR)
      IF ((p5b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_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+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p1b_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+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('beta_1_2_2_1_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('beta_1_2_2_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_2_2_1_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('
     &beta_1_2_2_1_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+h7b-1),int_mb(k_range+h4b-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),(p1b -
     & noab - 1 + nvab * (h11b - 1 + noab * (h7b - 1 + noab * (h4b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_2_2_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_2_2_1_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 beta_1_2_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h7 h10 h11 )_ytrctra + = 1 * Sum ( p1 ) * tra ( p1 h10 )_tra * i3 ( h4 h7 h11 p1 )_ytrc
      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 h7b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p1b
      INTEGER p1b_1
      INTEGER h10b_1
      INTEGER h4b_2
      INTEGER h7b_2
      INTEGER h11b_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 h4b = 1,noab
      DO h7b = h4b,noab
      DO h10b = 1,noab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h7b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h7b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trc,irrep_tra))) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h7b-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('beta_1_2_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p1b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p1b-1),int_mb(k_sym+h10b-1)) .eq. irrep_tra)
     & THEN
      CALL TCE_RESTRICTED_2(p1b,h10b,p1b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h4b,h7b,h11b,p1b,h4b_2,h7b_2,h11b_2,p1b_2)
      dim_common = int_mb(k_range+p1b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h7b-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('beta_1_2_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_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 * (p1b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_2_2_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_2_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_2_2_1',5,MA_ERR)
      IF ((h11b .le. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (h11b_2 - 1 + noab * (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+h11b-1),int_mb(k_range+p1b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_2_2_1',6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_2_2_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_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('
     &beta_1_2_2_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+h7b-1),int_mb(k_range+h4b-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 * (h7b - 1 + noab * (h4b - 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+h7b-1),int_mb(k_range+h4b-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 * (h7b - 1 + noab * (h4b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_2_2_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_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 beta_1_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h7 p8 h10 h11 )_ytrctratrb + = 1 * Sum ( h4 ) * trb ( p8 h4 )_trb * i2 ( h4 h7 h10 h11 )_ytrctra
      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 h7b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p8b_1
      INTEGER h4b_1
      INTEGER h7b_2
      INTEGER h4b_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 p8b = noab+1,noab+nvab
      DO h7b = 1,noab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h7b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h7b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trc,ieor(irrep_tra,irrep_trb)))) THEN
      dimc = int_mb(k_range+h7b-1) * int_mb(k_range+p8b-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('beta_1_2_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_trb) 
     &THEN
      CALL TCE_RESTRICTED_2(p8b,h4b,p8b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h7b,h4b,h10b,h11b,h7b_2,h4b_2,h10b_2,h11b_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+h7b-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('beta_1_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_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 * (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('beta_1_2_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_2_2',5,MA_ERR)
      IF ((h4b .le. h7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF ((h7b .lt. h4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,1,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_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('beta_1_2_2',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_2_2',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_2_2',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+h7b-1),int_mb(k_range+p8b-
     &1),3,4,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p8b - noab - 1 + nvab * (h7b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_2_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_2_2',11,MA_E
     &RR)
      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 beta_1_2_3_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i3 ( h2 h7 h11 p3 )_ytrc + = 1 * Sum ( p5 ) * trc ( p5 h11 )_trc * y ( h2 h7 p3 p5 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      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 h7b_2
      INTEGER p3b_2
      INTEGER p5b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h7b = h2b,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+h7b-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+h7b-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+h7b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_2_3_1_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_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h11b,p5b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,p3b,p5b,h2b_2,h7b_2,p3b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+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+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('beta_1_2_3_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_2_3_1_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('beta_1_2_3_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_2_3_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_2_3_1_1',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 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p3b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h7b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_2_3_1_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('beta_1_2_3_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_2_3_1_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('
     &beta_1_2_3_1_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+h2b-1),int_mb(k_range+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 * (h7b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_2_3_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_2_3_1_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 beta_1_2_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h10 h11 )_ytrctrb + = 1 * Sum ( p3 ) * trb ( p3 h10 )_trb * i3 ( h2 h7 h11 p3 )_ytrc
      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 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 h7b_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 h7b = h2b,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+h7b-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+h7b-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+h7b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trc,irrep_trb))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-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('beta_1_2_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+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h10b-1)) .eq. irrep_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p3b,h10b,p3b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,h11b,p3b,h2b_2,h7b_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+h7b-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('beta_1_2_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_2_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 * (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('beta_1_2_3_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_2_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_2_3_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 * (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+p3b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_2_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('beta_1_2_3_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_2_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('
     &beta_1_2_3_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+h7b-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 * (h7b - 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+h7b-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 * (h7b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_2_3_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_2_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 beta_1_2_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h7 p8 h10 h11 )_ytrctrbtra + = 1 * Sum ( h2 ) * tra ( p8 h2 )_tra * i2 ( h2 h7 h10 h11 )_ytrctrb
      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 h7b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h2b
      INTEGER p8b_1
      INTEGER h2b_1
      INTEGER h7b_2
      INTEGER h2b_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 p8b = noab+1,noab+nvab
      DO h7b = 1,noab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h7b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h7b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trc,ieor(irrep_trb,irrep_tra)))) THEN
      dimc = int_mb(k_range+h7b-1) * int_mb(k_range+p8b-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('beta_1_2_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h2b = 1,noab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h2b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+h2b-1)) .eq. irrep_tra) 
     &THEN
      CALL TCE_RESTRICTED_2(p8b,h2b,p8b_1,h2b_1)
      CALL TCE_RESTRICTED_4(h7b,h2b,h10b,h11b,h7b_2,h2b_2,h10b_2,h11b_2)
      dim_common = int_mb(k_range+h2b-1)
      dima_sort = int_mb(k_range+p8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h7b-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('beta_1_2_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_2_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h2b_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+h2b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_2_3',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_2_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_2_3',5,MA_ERR)
      IF ((h2b .le. h7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF ((h7b .lt. h2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,1,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_2_3',6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_2_3',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_2_3',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_2_3',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+h7b-1),int_mb(k_range+p8b-
     &1),3,4,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p8b - noab - 1 + nvab * (h7b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_2_3',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_2_3',11,MA_E
     &RR)
      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 beta_1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( )_ytrbtratrcv + = -1 * Sum ( h7 p8 h10 h11 ) * i1 ( h7 p8 h10 h11 )_ytrbtratrc * v ( h10 h11 h7 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 dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h7b
      INTEGER p8b
      INTEGER h10b
      INTEGER h11b
      INTEGER h7b_1
      INTEGER p8b_1
      INTEGER h10b_1
      INTEGER h11b_1
      INTEGER h10b_2
      INTEGER h11b_2
      INTEGER h7b_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)
      IF (next.eq.count) THEN
      IF (0 .eq. ieor(irrep_y,ieor(irrep_trb,ieor(irrep_tra,ieor(irrep_t
     &rc,irrep_v))))) THEN
      dimc = 1
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h7b = 1,noab
      DO p8b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (int_mb(k_spin+h7b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trb,ieor(irrep_tra,irrep_trc)))) THEN
      CALL TCE_RESTRICTED_4(h7b,p8b,h10b,h11b,h7b_1,p8b_1,h10b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h10b,h11b,h7b,p8b,h10b_2,h11b_2,h7b_2,p8b_2)
      dim_common = int_mb(k_range+h7b-1) * int_mb(k_range+p8b-1) * int_m
     &b(k_range+h10b-1) * int_mb(k_range+h11b-1)
      dima_sort = 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('beta_1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_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 * (h10b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (h7
     &b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+p8b-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('beta_1_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_2',5,MA_ERR)
      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) * (h7b_2 - 1 + (noab+nvab) * (h11b_2 - 1 + (noa
     &b+nvab) * (h10b_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) * (h7b_2 - 1 + (noab+nvab) * (h11b_2 - 1 + (noa
     &b+nvab) * (h10b_2 - 1)))),p8b_2,h7b_2,h11b_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+h11b-1),int_mb(k_range+h7b-1),int_mb(k_range+p8b-
     &1),2,1,4,3,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_2',6,MA_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h10b .eq. h11b) 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('beta_1_2',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_2',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_2',9,MA_ERR)
      CALL TCE_SORT_0(dbl_mb(k_c_sort),dbl_mb(k_c),-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),0)
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_2',11,MA_ERR
     &)
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE beta_1_3_1_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p9 h11 p3 )_vtrc + = -1 * Sum ( p5 ) * trc ( p5 h11 )_trc * v ( h2 p9 p3 p5 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER 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 p5b
      INTEGER p5b_1
      INTEGER h11b_1
      INTEGER h2b_2
      INTEGER p9b_2
      INTEGER p3b_2
      INTEGER p5b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL 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_trc))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_1_1_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_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h11b,p5b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,p9b,p3b,p5b,h2b_2,p9b_2,p3b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+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('beta_1_3_1_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_1_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('beta_1_3_1_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_1_1',5,MA_ERR)
      IF ((p5b .lt. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p3b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p5b_2,p9b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p3b .le. p5b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p3b_2,p9b_2,h2b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_1_1_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('beta_1_3_1_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_1_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('
     &beta_1_3_1_1_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('beta_1_3_1_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_1_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 beta_1_3_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h10 h11 )_vtrctrb + = 1 * Sum ( p3 ) * trb ( p3 h10 )_trb * i3 ( h2 p9 h11 p3 )_vtrc
      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
     &_trc,irrep_trb))) 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('beta_1_3_1_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_trb)
     & THEN
      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('beta_1_3_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_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('beta_1_3_1_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_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 * (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('beta_1_3_1_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('beta_1_3_1_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_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('
     &beta_1_3_1_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+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('beta_1_3_1_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h6 h11 p4 )_vtrc + = 1 * Sum ( p7 ) * trc ( p7 h11 )_trc * 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 = h2b,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_trc))
     & THEN
      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('beta_1_3_1_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_trc)
     & THEN
      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('beta_1_3_1_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_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('beta_1_3_1_2_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_2_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) * (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 ((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('beta_1_3_1_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('beta_1_3_1_2_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_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('
     &beta_1_3_1_2_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('beta_1_3_1_2_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h10 h11 )_vtrctrb + = -1 * Sum ( h6 p4 ) * trb ( p4 p9 h6 h10 )_trb * i3 ( h2 h6 h11 p4 )_vtrc
      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 h2b
      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 p9b = noab+1,noab+nvab
      DO h2b = 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+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
     &_trc,irrep_trb))) 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('beta_1_3_1_2',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_trb) 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('beta_1_3_1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_2',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('beta_1_3_1_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_2',5,MA_ERR)
      IF ((h6b .lt. h2b) .and. (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 * (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+h11b-1),int_mb(k_range+p4b-1
     &),3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h6b) .and. (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('beta_1_3_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('beta_1_3_1_2',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_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('
     &beta_1_3_1_2',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('beta_1_3_1_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_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 beta_1_3_1_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h11 )_vtrb + = -1 * Sum ( p3 p4 ) * trb ( p3 p4 h10 h11 )_trb * 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 = h2b,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_trb)
     &) 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('beta_1_3_1_3_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+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_trb) 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('beta_1_3_1_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_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 * (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('beta_1_3_1_3_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_3_1',5,MA_ERR)
      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)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_1_3_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('beta_1_3_1_3_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_3_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('
     &beta_1_3_1_3_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+h11b-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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_1_3_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h10 h11 )_vtrbtrc + = -1/4 * Sum ( h8 ) * trc ( p9 h8 )_trc * i3 ( h2 h8 h10 h11 )_vtrb
      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 h2b
      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 p9b = noab+1,noab+nvab
      DO h2b = 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+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
     &_trb,irrep_trc))) 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('beta_1_3_1_3',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_trc) 
     &THEN
      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('beta_1_3_1_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_3',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('beta_1_3_1_3',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_3',5,MA_ERR)
      IF ((h8b .lt. h2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,-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),(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)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_1_3',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_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('
     &beta_1_3_1_3',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/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('beta_1_3_1_3',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p4 )_vtrc + = 1 * Sum ( h8 p7 ) * trc ( p7 h8 )_trc * v ( h2 h8 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 p4b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h8b
      INTEGER p7b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER 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 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_trc)) 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('beta_1_3_1_4_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO h8b = 1,noab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h8b-1)) .eq. irrep_trc) 
     &THEN
      CALL TCE_RESTRICTED_2(p7b,h8b,p7b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,p4b,p7b,h2b_2,h8b_2,p4b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+h8b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+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('beta_1_3_1_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_4_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_1_4_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_4_1',5,MA_ERR)
      IF ((h8b .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) * (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) * (p7b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p4b_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+p4b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h8b .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) * (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) * (p4b_2 - 1 + (noab+nvab) * (h2b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p7b_2,p4b_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+p4b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .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) * (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) * (p7b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p4b_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+p4b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .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) * (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) * (p4b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p7b_2,p4b_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+p4b-1),int_mb(k_range+p7b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_1_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('beta_1_3_1_4_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_4_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('
     &beta_1_3_1_4_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('beta_1_3_1_4_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h10 h11 )_vtrctrb + = -1/2 * Sum ( p4 ) * trb ( p4 p9 h10 h11 )_trb * i3 ( h2 p4 )_vtrc
      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 h2b
      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 p9b = noab+1,noab+nvab
      DO h2b = 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+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
     &_trc,irrep_trb))) 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('beta_1_3_1_4',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_trb) 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('beta_1_3_1_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_4',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('beta_1_3_1_4',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_4',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p4b_2
     & - noab - 1 + nvab * (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('beta_1_3_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('beta_1_3_1_4',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_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('
     &beta_1_3_1_4',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h2b-1)
     &,int_mb(k_range+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('beta_1_3_1_4',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1_5_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p6 )_vtrb + = 1 * Sum ( p3 ) * trb ( p3 h10 )_trb * v ( h2 h8 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 h8b
      INTEGER h10b
      INTEGER p6b
      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 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 h8b = h2b,noab
      DO h10b = 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+h8b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p6b-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+p6b-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+p6b-1)))) .eq. ieor(irrep_v,irrep_trb))
     & 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+p6b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p3b,h10b,p3b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,p6b,p3b,h2b_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+h2b-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('beta_1_3_1_5_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_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('beta_1_3_1_5_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_5_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_5_1',5,MA_ERR)
      IF ((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) * (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) * (p3b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p6b_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+p6b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((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) * (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) * (p6b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p3b_2,p6b_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+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('beta_1_3_1_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('beta_1_3_1_5_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_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('
     &beta_1_3_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+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),(p6b -
     & noab - 1 + nvab * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_1_5_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_5_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 beta_1_3_1_5(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h10 h11 )_vtrbtrc + = -1 * Sum ( h8 p6 ) * trc ( p6 p9 h8 h11 )_trc * i3 ( h2 h8 h10 p6 )_vtrb
      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 h2b
      INTEGER h11b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p6b
      INTEGER h8b
      INTEGER p9b_1
      INTEGER p6b_1
      INTEGER h11b_1
      INTEGER h8b_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 p9b = noab+1,noab+nvab
      DO h2b = 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+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
     &_trb,irrep_trc))) 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('beta_1_3_1_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p6b = noab+1,noab+nvab
      DO h8b = 1,noab
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p6b-1) .eq. int_mb(k_spin+h
     &11b-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+h11b-1),int_mb(k_sym+h8b-1)))) .eq. irrep_trc) THEN
      CALL TCE_RESTRICTED_4(p9b,p6b,h11b,h8b,p9b_1,p6b_1,h11b_1,h8b_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) * int_mb(k_range+h8b-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('beta_1_3_1_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_5',2,MA_ERR)
      IF ((p6b .le. p9b) .and. (h8b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h8b_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+h8b-1),int_mb(k_range+h11b-1
     &),4,2,3,1,1.0d0)
      END IF
      IF ((p6b .le. p9b) .and. (h11b .lt. h8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h11b_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+h11b-1),int_mb(k_range+h8b-1
     &),3,2,4,1,-1.0d0)
      END IF
      IF ((p9b .lt. p6b) .and. (h8b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h8b_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+h8b-1),int_mb(k_range+h11b-1
     &),4,1,3,2,-1.0d0)
      END IF
      IF ((p9b .lt. p6b) .and. (h11b .lt. h8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h11b_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+h11b-1),int_mb(k_range+h8b-1
     &),3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_1_5',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_5',5,MA_ERR)
      IF ((h8b .lt. h2b) .and. (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 * (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+h10b-1),int_mb(k_range+p6b-1
     &),3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h8b) .and. (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 * (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+p6b-1
     &),3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_1_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('beta_1_3_1_5',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_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('
     &beta_1_3_1_5',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('beta_1_3_1_5',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1_6_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h11 )_vtrc + = -1 * Sum ( p5 p6 ) * trc ( p5 p6 h10 h11 )_trc * v ( h2 h4 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 h4b
      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 h4b_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 h4b = h2b,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+h4b-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+h4b-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+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,irrep_trc)
     &) 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+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_1_6_1',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_trc) THEN
      CALL TCE_RESTRICTED_4(p5b,p6b,h10b,h11b,p5b_1,p6b_1,h10b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p5b,p6b,h2b_2,h4b_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+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('beta_1_3_1_6_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_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 * (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('beta_1_3_1_6_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_6_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_6_1',5,MA_ERR)
      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) * (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) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p6b_2,p5b_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+p5b-1),int_mb(k_range+p6b-1)
     &,2,1,4,3,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_1_6_1',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('beta_1_3_1_6_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_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('
     &beta_1_3_1_6_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+h11b-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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_1_6_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1_6(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h10 h11 )_vtrctrb + = -1/4 * Sum ( h4 ) * trb ( p9 h4 )_trb * i3 ( h2 h4 h10 h11 )_vtrc
      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 h2b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p9b_1
      INTEGER h4b_1
      INTEGER h2b_2
      INTEGER h4b_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 p9b = noab+1,noab+nvab
      DO h2b = 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+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
     &_trc,irrep_trb))) 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('beta_1_3_1_6',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_trb) 
     &THEN
      CALL TCE_RESTRICTED_2(p9b,h4b,p9b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h10b,h11b,h2b_2,h4b_2,h10b_2,h11b_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+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('beta_1_3_1_6',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_6',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('beta_1_3_1_6',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_6',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_6',5,MA_ERR)
      IF ((h4b .lt. h2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,-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),(h11b_
     &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+h11b-
     &1),4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_1_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('beta_1_3_1_6',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_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('
     &beta_1_3_1_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/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('beta_1_3_1_6',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1_7_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p6 )_vtrb + = 1 * Sum ( h4 p3 ) * trb ( p3 h4 )_trb * 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_trb)) 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('beta_1_3_1_7_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_trb) 
     &THEN
      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('beta_1_3_1_7_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_7_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('beta_1_3_1_7_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_7_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_7_1',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('beta_1_3_1_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('beta_1_3_1_7_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_7_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('
     &beta_1_3_1_7_1',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('beta_1_3_1_7_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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
c done till here 2/7/2014 11am
      SUBROUTINE beta_1_3_1_7(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h10 h11 )_vtrbtrc + = 1/2 * Sum ( p6 ) * trc ( p6 p9 h10 h11 )_trc * i3 ( h2 p6 )_vtrb
      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 h2b
      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 p9b = noab+1,noab+nvab
      DO h2b = 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+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
     &_trb,irrep_trc))) 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('beta_1_3_1_7',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_trc) 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('beta_1_3_1_7',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_7',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('beta_1_3_1_7',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_7',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_7',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('beta_1_3_1_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('beta_1_3_1_7',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_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('
     &beta_1_3_1_7',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('beta_1_3_1_7',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1_8_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i4 ( h2 h4 h11 p5 )_vtrc + = 1 * Sum ( p7 ) * trc ( p7 h11 )_trc * v ( h2 h4 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 h2b
      INTEGER h4b
      INTEGER h11b
      INTEGER p5b
      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 p5b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h4b = h2b,noab
      DO h11b = 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+h11b-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
     &11b-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+h11b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_v,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_1_8_1_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_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p7b,h11b,p7b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p5b,p7b,h2b_2,h4b_2,p5b_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+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('beta_1_3_1_8_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_8_1_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('beta_1_3_1_8_1_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_8_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_8_1_1',5,MA_ERR)
      IF ((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) * (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),
     &(p5b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p7b_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+p7b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((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) * (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),
     &(p7b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p7b_2,p5b_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+p5b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_1_8_1_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('beta_1_3_1_8_1_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_8_1_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('
     &beta_1_3_1_8_1_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+h11b-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 * (h11b - 1 + noab * (h4b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_1_8_1_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_8_1_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 beta_1_3_1_8_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h11 )_vtrctrb + = 1 * Sum ( p5 ) * trb ( p5 h10 )_trb * i4 ( h2 h4 h11 p5 )_vtrc
      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 h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h11b_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 = h2b,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+h4b-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+h4b-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+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irrep
     &_trc,irrep_trb))) 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+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_1_8_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h10b,p5b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h11b,p5b,h2b_2,h4b_2,h11b_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+h4b-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('beta_1_3_1_8_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_8_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('beta_1_3_1_8_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_8_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_8_1',5,MA_ERR)
      IF ((h11b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_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+p5b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_1_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('beta_1_3_1_8_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_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('
     &beta_1_3_1_8_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+h4b-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 * (h4b - 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+h4b-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 * (h4b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_1_8_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1_8(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h10 h11 )_vtrctrbt + = 1/2 * Sum ( h4 ) * t ( p9 h4 )_t * i3 ( h2 h4 h10 h11 )_vtrctrb
      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 h2b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p9b_1
      INTEGER h4b_1
      INTEGER h2b_2
      INTEGER h4b_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 p9b = noab+1,noab+nvab
      DO h2b = 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+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
     &_trc,ieor(irrep_trb,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('beta_1_3_1_8',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_4(h2b,h4b,h10b,h11b,h2b_2,h4b_2,h10b_2,h11b_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+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('beta_1_3_1_8',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1_8',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('beta_1_3_1_8',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1_8',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1_8',5,MA_ERR)
      IF ((h4b .lt. h2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,-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),(h11b_
     &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+h11b-
     &1),4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_1_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('beta_1_3_1_8',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1_8',8,MA_
     &ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_3_1_8',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/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('beta_1_3_1_8',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1_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 beta_1_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h11 )_vtrctrbtra + = 1 * Sum ( h2 ) * tra ( p12 h2 )_tra * i2 ( h2 p9 h10 h11 )_vtrctrb
      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 p12b
      INTEGER p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h2b
      INTEGER p12b_1
      INTEGER h2b_1
      INTEGER p9b_2
      INTEGER h2b_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 p12b = noab+1,noab+nvab
      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+p9b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irre
     &p_trc,ieor(irrep_trb,irrep_tra)))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+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('beta_1_3_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h2b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h2b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h2b-1)) .eq. irrep_tra)
     & THEN
      CALL TCE_RESTRICTED_2(p12b,h2b,p12b_1,h2b_1)
      CALL TCE_RESTRICTED_4(p9b,h2b,h10b,h11b,p9b_2,h2b_2,h10b_2,h11b_2)
      dim_common = int_mb(k_range+h2b-1)
      dima_sort = int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p9b-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('beta_1_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h2b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h2b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_1',5,MA_ERR)
      IF ((h2b .le. p9b)) THEN
      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),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_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('beta_1_3_1',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_1',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_3_1',9,MA_ERR)
      IF ((p9b .le. p12b)) THEN
      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+p9b-1),int_mb(k_range+p12b
     &-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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (p9b - n
     &oab - 1)))))
      END IF
      IF ((p12b .le. p9b)) THEN
      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+p9b-1),int_mb(k_range+p12b
     &-1),4,3,2,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 * (p12b - n
     &oab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_1',11,MA_E
     &RR)
      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 beta_1_3_2_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h4 p9 h11 p1 )_vtrc + = -1 * Sum ( p5 ) * trc ( p5 h11 )_trc * v ( h4 p9 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 h4b
      INTEGER p9b
      INTEGER h11b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h11b_1
      INTEGER h4b_2
      INTEGER p9b_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 h4b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 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+p9b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_v,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_2_1_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_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h11b,p5b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h4b,p9b,p1b,p5b,h4b_2,p9b_2,p1b_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+h4b-1) * int_mb(k_range+p9b-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('beta_1_3_2_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_2_1_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('beta_1_3_2_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_2_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_2_1_1',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) * (p9b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p1b_2,p5b_2,p9b_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+p9b-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) * (p9b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p5b_2,p1b_2,p9b_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+p9b-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('beta_1_3_2_1_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('beta_1_3_2_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_2_1_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('
     &beta_1_3_2_1_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+p9b-1),int_mb(k_range+h4b-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),(p1b -
     & noab - 1 + nvab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h4
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_2_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_2_1_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 beta_1_3_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p9 h10 h11 )_vtrctra + = 1 * Sum ( p1 ) * tra ( p1 h10 )_tra * i3 ( h4 p9 h11 p1 )_vtrc
      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 p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p1b
      INTEGER p1b_1
      INTEGER h10b_1
      INTEGER h4b_2
      INTEGER p9b_2
      INTEGER h11b_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 h4b = 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+h4b-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+h4b-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+h4b-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
     &_trc,irrep_tra))) THEN
      dimc = int_mb(k_range+h4b-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('beta_1_3_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p1b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p1b-1),int_mb(k_sym+h10b-1)) .eq. irrep_tra)
     & THEN
      CALL TCE_RESTRICTED_2(p1b,h10b,p1b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h4b,p9b,h11b,p1b,h4b_2,p9b_2,h11b_2,p1b_2)
      dim_common = int_mb(k_range+p1b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-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('beta_1_3_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_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 * (p1b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_2_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_2_1',5,MA_ERR)
      IF ((h11b .le. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (h11b_2 - 1 + noab * (p9b_2 - noab - 1 + nvab
     & * (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+p9b-1),int_mb(k_range+h11b-1),int_mb(k_range+p1b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_2_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_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('
     &beta_1_3_2_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+p9b-1),int_mb(k_range+h4b-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 * (h4b - 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+h4b-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 * (h4b - 1)
     &))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_2_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_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 beta_1_3_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h11 )_vtrctratrb + = 1 * Sum ( h4 ) * trb ( p12 h4 )_trb * i2 ( h4 p9 h10 h11 )_vtrctra
      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 p12b
      INTEGER p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p12b_1
      INTEGER h4b_1
      INTEGER p9b_2
      INTEGER h4b_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 p12b = noab+1,noab+nvab
      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+p9b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irre
     &p_trc,ieor(irrep_tra,irrep_trb)))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+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('beta_1_3_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h4b-1)) .eq. irrep_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p12b,h4b,p12b_1,h4b_1)
      CALL TCE_RESTRICTED_4(p9b,h4b,h10b,h11b,p9b_2,h4b_2,h10b_2,h11b_2)
      dim_common = int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p9b-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('beta_1_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_2',5,MA_ERR)
      IF ((h4b .le. p9b)) THEN
      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 * (h4
     &b_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+p9b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_2',6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_3_2',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_2',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_3_2',9,MA_ERR)
      IF ((p9b .le. p12b)) THEN
      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+p9b-1),int_mb(k_range+p12b
     &-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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (p9b - n
     &oab - 1)))))
      END IF
      IF ((p12b .le. p9b)) THEN
      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+p9b-1),int_mb(k_range+p12b
     &-1),4,3,2,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 * (p12b - n
     &oab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_2',11,MA_E
     &RR)
      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 beta_1_3_3_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h6 p9 h11 p1 )_vtrb + = -1 * Sum ( p3 ) * trb ( p3 h11 )_trb * v ( h6 p9 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 h6b
      INTEGER p9b
      INTEGER h11b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h11b_1
      INTEGER h6b_2
      INTEGER p9b_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 h6b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h6b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      IF (int_mb(k_spin+h6b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h6b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_v,irrep_trb))
     & THEN
      dimc = int_mb(k_range+h6b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_3_1_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p3b,h11b,p3b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h6b,p9b,p1b,p3b,h6b_2,p9b_2,p1b_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+h6b-1) * int_mb(k_range+p9b-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('beta_1_3_3_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_3_1_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('beta_1_3_3_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_3_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_3_1_1',5,MA_ERR)
      IF ((p3b .lt. p1b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p1b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p1b_2,p3b_2,p9b_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+p9b-1),int_mb(k_range+p3b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p3b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p9b_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) * (p1b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p3b_2,p1b_2,p9b_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+p9b-1),int_mb(k_range+p1b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_3_1_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('beta_1_3_3_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_3_1_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('
     &beta_1_3_3_1_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+p9b-1),int_mb(k_range+h6b-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),(p1b -
     & noab - 1 + nvab * (h11b - 1 + noab * (p9b - noab - 1 + nvab * (h6
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_3_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_3_1_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 beta_1_3_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p9 h10 h11 )_vtrbtra + = 1 * Sum ( p1 ) * tra ( p1 h10 )_tra * i3 ( h6 p9 h11 p1 )_vtrb
      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 p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p1b
      INTEGER p1b_1
      INTEGER h10b_1
      INTEGER h6b_2
      INTEGER p9b_2
      INTEGER h11b_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 h6b = 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+h6b-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+h6b-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+h6b-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
     &_trb,irrep_tra))) THEN
      dimc = int_mb(k_range+h6b-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('beta_1_3_3_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p1b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p1b-1),int_mb(k_sym+h10b-1)) .eq. irrep_tra)
     & THEN
      CALL TCE_RESTRICTED_2(p1b,h10b,p1b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h6b,p9b,h11b,p1b,h6b_2,p9b_2,h11b_2,p1b_2)
      dim_common = int_mb(k_range+p1b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-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('beta_1_3_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_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 * (p1b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_3_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_3_1',5,MA_ERR)
      IF ((h11b .le. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (h11b_2 - 1 + noab * (p9b_2 - noab - 1 + nvab
     & * (h6b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h11b-1),int_mb(k_range+p1b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_3_1',6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_3_3_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_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('
     &beta_1_3_3_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+p9b-1),int_mb(k_range+h6b-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 * (h6b - 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+h6b-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 * (h6b - 1)
     &))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_3_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_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 beta_1_3_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h11 )_vtrbtratrc + = 1 * Sum ( h6 ) * trc ( p12 h6 )_trc * i2 ( h6 p9 h10 h11 )_vtrbtra
      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 p12b
      INTEGER p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h6b
      INTEGER p12b_1
      INTEGER h6b_1
      INTEGER p9b_2
      INTEGER h6b_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 p12b = noab+1,noab+nvab
      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+p9b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irre
     &p_trb,ieor(irrep_tra,irrep_trc)))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+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('beta_1_3_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h6b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h6b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p12b,h6b,p12b_1,h6b_1)
      CALL TCE_RESTRICTED_4(p9b,h6b,h10b,h11b,p9b_2,h6b_2,h10b_2,h11b_2)
      dim_common = int_mb(k_range+h6b-1)
      dima_sort = int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p9b-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('beta_1_3_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h6b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_3',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_3',5,MA_ERR)
      IF ((h6b .le. p9b)) THEN
      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 * (h6
     &b_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+p9b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_3',6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_3_3',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_3',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_3_3',9,MA_ERR)
      IF ((p9b .le. p12b)) THEN
      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+p9b-1),int_mb(k_range+p12b
     &-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),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (p9b - n
     &oab - 1)))))
      END IF
      IF ((p12b .le. p9b)) THEN
      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+p9b-1),int_mb(k_range+p12b
     &-1),4,3,2,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 * (p12b - n
     &oab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_3',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_3',11,MA_E
     &RR)
      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 beta_1_3_4_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p1 )_vtrb + = 1 * Sum ( h4 p3 ) * trb ( p3 h4 )_trb * v ( h4 h8 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 h8b
      INTEGER p1b
      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 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 h8b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_trb)) THEN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_4_1_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_trb) 
     &THEN
      CALL TCE_RESTRICTED_2(p3b,h4b,p3b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h8b,h4b,p1b,p3b,h8b_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+h8b-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('beta_1_3_4_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_4_1_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('beta_1_3_4_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_4_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_4_1_1',5,MA_ERR)
      IF ((h4b .le. h8b) .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) * (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),
     &(p1b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p1b_2,p3b_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+p3b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h4b .le. h8b) .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) * (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) * (p1b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p3b_2,p1b_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+p1b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF ((h8b .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) * (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) * (p3b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p1b_2,p3b_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+p3b-1),int_mb(k_range+p1b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h8b .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) * (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) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p3b_2,p1b_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+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('beta_1_3_4_1_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('beta_1_3_4_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_4_1_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('
     &beta_1_3_4_1_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+h8b-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 * (h8b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_4_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_4_1_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 beta_1_3_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h10 )_vtrbtra + = 1 * Sum ( p1 ) * tra ( p1 h10 )_tra * i3 ( h8 p1 )_vtrb
      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 h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p1b
      INTEGER p1b_1
      INTEGER h10b_1
      INTEGER h8b_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 h8b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+h10b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+h10b-1)) .eq. ieor(irrep
     &_v,ieor(irrep_trb,irrep_tra))) THEN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+h10b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_4_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p1b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p1b-1),int_mb(k_sym+h10b-1)) .eq. irrep_tra)
     & THEN
      CALL TCE_RESTRICTED_2(p1b,h10b,p1b_1,h10b_1)
      CALL TCE_RESTRICTED_2(h8b,p1b,h8b_2,p1b_2)
      dim_common = int_mb(k_range+p1b-1)
      dima_sort = int_mb(k_range+h10b-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('beta_1_3_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_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 * (p1b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_4_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_4_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_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+p1b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_4_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_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('
     &beta_1_3_4_1',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+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 * (h8b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_4_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_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 beta_1_3_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h11 )_vtrbtratrc + = -1/2 * Sum ( h8 ) * trc ( p9 p12 h8 h11 )_trc * i2 ( h8 h10 )_vtrbtra
      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 p12b
      INTEGER h11b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p9b_1
      INTEGER p12b_1
      INTEGER h11b_1
      INTEGER h8b_1
      INTEGER h8b_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 p12b = p9b,noab+nvab
      DO h11b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irre
     &p_trb,ieor(irrep_tra,irrep_trc)))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+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('beta_1_3_4',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)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h11b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h11b-1),int_mb(k_sym+h8b-1)))) .eq. irrep_trc) THEN
      CALL TCE_RESTRICTED_4(p9b,p12b,h11b,h8b,p9b_1,p12b_1,h11b_1,h8b_1)
      CALL TCE_RESTRICTED_2(h8b,h10b,h8b_2,h10b_2)
      dim_common = int_mb(k_range+h8b-1)
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+p12b-1) * int_m
     &b(k_range+h11b-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('beta_1_3_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_4',2,MA_ERR)
      IF ((h8b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h8b_1 - 1 + noab * (p12b_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+p12b-1),int_mb(k_range+h8b-1),int_mb(k_range+h11b-
     &1),4,2,1,3,1.0d0)
      END IF
      IF ((h11b .lt. h8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (h11b_1 - 1 + noab * (p12b_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+p12b-1),int_mb(k_range+h11b-1),int_mb(k_range+h8b-
     &1),3,2,1,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_4',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_4',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h10b_
     &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+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_4',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_4',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_3_4',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+h11b-1),int_mb(k_range+p12b-1),int_mb(k_range+p9b
     &-1),4,3,1,2,-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 * (p12b - noab - 1 + nvab * (p9b - n
     &oab - 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+h11b-1),int_mb(k_range+p12b-1),int_mb(k_range+p9b
     &-1),4,3,2,1,1.0d0/4.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h11b - 1 + noab * (p12b - noab - 1 + nvab * (p9b - n
     &oab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_4',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_4',11,MA_E
     &RR)
      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 beta_1_3_5_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h3 h4 h11 p5 )_vtrc + = -1 * Sum ( p7 ) * trc ( p7 h11 )_trc * v ( h3 h4 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 h3b
      INTEGER h4b
      INTEGER h11b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h11b_1
      INTEGER h3b_2
      INTEGER h4b_2
      INTEGER p5b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h3b = 1,noab
      DO h4b = h3b,noab
      DO h11b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h3b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p5b-1).ne.8)) THEN
      IF (int_mb(k_spin+h3b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h3b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_v,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h3b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_5_1_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_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p7b,h11b,p7b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h3b,h4b,p5b,p7b,h3b_2,h4b_2,p5b_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+h3b-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('beta_1_3_5_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_5_1_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('beta_1_3_5_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_5_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_5_1_1',5,MA_ERR)
      IF ((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) * (h4b_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) * (p7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h3b_2 - 1)))),p5b_2,p7b_2,h4b_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+h4b-1),int_mb(k_range+p7b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((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) * (h4b_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),
     &(p7b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h3b_2 - 1)))),p7b_2,p5b_2,h4b_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+h4b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_5_1_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('beta_1_3_5_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_5_1_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('
     &beta_1_3_5_1_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+h3b-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),(p5b -
     & noab - 1 + nvab * (h11b - 1 + noab * (h4b - 1 + noab * (h3b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_5_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_5_1_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 beta_1_3_5_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h3 h4 h10 h11 )_vtrctrb + = 1 * Sum ( p5 ) * trb ( p5 h10 )_trb * i3 ( h3 h4 h11 p5 )_vtrc
      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 h3b
      INTEGER h4b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h10b_1
      INTEGER h3b_2
      INTEGER h4b_2
      INTEGER h11b_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 h3b = 1,noab
      DO h4b = h3b,noab
      DO h10b = 1,noab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h3b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h3b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h3b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irrep
     &_trc,irrep_trb))) THEN
      dimc = int_mb(k_range+h3b-1) * int_mb(k_range+h4b-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('beta_1_3_5_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h10b,p5b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h3b,h4b,h11b,p5b,h3b_2,h4b_2,h11b_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+h3b-1) * int_mb(k_range+h4b-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('beta_1_3_5_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_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 * (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('beta_1_3_5_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_5_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_5_1',5,MA_ERR)
      IF ((h11b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (h11b_2 - 1 + noab * (h4b_2 - 1 + noab * (h3b
     &_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h11b-1),int_mb(k_range+p5b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_5_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_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('
     &beta_1_3_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+h4b-1),int_mb(k_range+h3b-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 * (h4b - 1 + noab * (h3b - 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+h4b-1),int_mb(k_range+h3b-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 * (h4b - 1 + noab * (h3b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_5_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_5_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 beta_1_3_5(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h11 )_vtrctrbtra + = 1/4 * Sum ( h3 h4 ) * tra ( p9 p12 h3 h4 )_tra * i2 ( h3 h4 h10 h11 )_vtrctrb
      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 p12b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h3b
      INTEGER h4b
      INTEGER p9b_1
      INTEGER p12b_1
      INTEGER h3b_1
      INTEGER h4b_1
      INTEGER h3b_2
      INTEGER h4b_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 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 p12b = p9b,noab+nvab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irre
     &p_trc,ieor(irrep_trb,irrep_tra)))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+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('beta_1_3_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h3b = 1,noab
      DO h4b = h3b,noab
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h3b-1)+int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h3b-1),int_mb(k_sym+h4b-1)))) .eq. irrep_tra) THEN
      CALL TCE_RESTRICTED_4(p9b,p12b,h3b,h4b,p9b_1,p12b_1,h3b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h3b,h4b,h10b,h11b,h3b_2,h4b_2,h10b_2,h11b_2)
      dim_common = int_mb(k_range+h3b-1) * int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h10b-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('beta_1_3_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_5',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (h3b_1 - 1 + noab * (p12b_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+p12b-1),int_mb(k_range+h3b-1),int_mb(k_range+h4b-1
     &),2,1,4,3,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_5',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_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 * (h4b_2 - 1 + noab * (h3b_2 - 1
     &)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h4b-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_b)) CALL ERRQUIT('beta_1_3_5',6,MA_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h3b .eq. h4b) 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('beta_1_3_5',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_5',8,MA_ER
     &R)
      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('
     &beta_1_3_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+p12b-1),int_mb(k_range+p9b
     &-1),4,3,2,1,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 * (p12b - noab - 1 + nvab * (p9b - n
     &oab - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_5',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_5',11,MA_E
     &RR)
      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 beta_1_3_6_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h4 h8 h11 p2 )_vtrb + = 1 * Sum ( p5 ) * trb ( p5 h11 )_trb * v ( h4 h8 p2 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 h4b
      INTEGER h8b
      INTEGER h11b
      INTEGER p2b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h11b_1
      INTEGER h4b_2
      INTEGER h8b_2
      INTEGER p2b_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 h8b = h4b,noab
      DO h11b = 1,noab
      DO p2b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p2b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p2b-1)))) .eq. ieor(irrep_v,irrep_trb))
     & THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+p2b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_6_1_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h11b,p5b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h4b,h8b,p2b,p5b,h4b_2,h8b_2,p2b_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+h4b-1) * int_mb(k_range+h8b-1) * int_mb
     &(k_range+p2b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('beta_1_3_6_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_6_1_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('beta_1_3_6_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_6_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_6_1_1',5,MA_ERR)
      IF ((p5b .lt. p2b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - 1 + (noab+nvab) * (p5b_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),
     &(p2b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p2b_2,p5b_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+p5b-1),int_mb(k_range+p2b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p2b .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) * (p2b_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),
     &(p5b_2
     & - 1 + (noab+nvab) * (p2b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p5b_2,p2b_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+p2b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_6_1_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('beta_1_3_6_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_6_1_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('
     &beta_1_3_6_1_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p2b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+h4b-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),(p2b -
     & noab - 1 + nvab * (h11b - 1 + noab * (h8b - 1 + noab * (h4b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_6_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_6_1_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 beta_1_3_6_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h11 )_vtrbtra + = 1 * Sum ( h4 p2 ) * tra ( p2 p12 h4 h10 )_tra * i3 ( h4 h8 h11 p2 )_vtrb
      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 p12b
      INTEGER h8b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p2b
      INTEGER h4b
      INTEGER p12b_1
      INTEGER p2b_1
      INTEGER h10b_1
      INTEGER h4b_1
      INTEGER h8b_2
      INTEGER h4b_2
      INTEGER h11b_2
      INTEGER p2b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p12b = noab+1,noab+nvab
      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+h8b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h8b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irre
     &p_trb,irrep_tra))) THEN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+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('beta_1_3_6_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p2b = noab+1,noab+nvab
      DO h4b = 1,noab
      IF (int_mb(k_spin+p12b-1)+int_mb(k_spin+p2b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),ieor(int_mb(k_sym+p2b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h4b-1)))) .eq. irrep_tra) THEN
      CALL TCE_RESTRICTED_4(p12b,p2b,h10b,h4b,p12b_1,p2b_1,h10b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h8b,h4b,h11b,p2b,h8b_2,h4b_2,h11b_2,p2b_2)
      dim_common = int_mb(k_range+p2b-1) * int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p12b-1) * int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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('beta_1_3_6_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_6_1',2,MA_ERR)
      IF ((p2b .le. p12b) .and. (h4b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h4b_1 - 1 + noab * (p12b_1 - noab - 1 + nvab * (p2
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p12b-1),int_mb(k_range+h4b-1),int_mb(k_range+h10b-
     &1),4,2,3,1,1.0d0)
      END IF
      IF ((p2b .le. p12b) .and. (h10b .lt. h4b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p12b_1 - noab - 1 + nvab * (p2
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+h4b-
     &1),3,2,4,1,-1.0d0)
      END IF
      IF ((p12b .lt. p2b) .and. (h4b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h4b_1 - 1 + noab * (p2b_1 - noab - 1 + nvab * (p12
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+h4b-1),int_mb(k_range+h10b-
     &1),4,1,3,2,-1.0d0)
      END IF
      IF ((p12b .lt. p2b) .and. (h10b .lt. h4b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p2b_1 - noab - 1 + nvab * (p12
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+h10b-1),int_mb(k_range+h4b-
     &1),3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_6_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_6_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_6_1',5,MA_ERR)
      IF ((h4b .le. h8b) .and. (h11b .le. p2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (h11b_2 - 1 + noab * (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+h11b-1),int_mb(k_range+p2b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF ((h8b .lt. h4b) .and. (h11b .le. p2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (h11b_2 - 1 + noab * (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+h11b-1),int_mb(k_range+p2b-1
     &),3,1,2,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_6_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_6_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('
     &beta_1_3_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+h11b-1
     &),int_mb(k_range+h8b-1),int_mb(k_range+h10b-1),int_mb(k_range+p12b
     &-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 * (p12b - noab - 1 + nvab * (h8b - 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+h10b-1),int_mb(k_range+p12b
     &-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 * (p12b - noab - 1 + nvab * (h8b - 1
     &)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_6_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_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 beta_1_3_6_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p2 )_vtrb + = 1 * Sum ( h6 p5 ) * trb ( p5 h6 )_trb * v ( h6 h8 p2 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 h8b
      INTEGER p2b
      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 p2b_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 p2b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+p2b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+p2b-1)) .eq. ieor(irrep_
     &v,irrep_trb)) THEN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+p2b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_6_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO h6b = 1,noab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h6b-1)) .eq. irrep_trb) 
     &THEN
      CALL TCE_RESTRICTED_2(p5b,h6b,p5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h8b,h6b,p2b,p5b,h8b_2,h6b_2,p2b_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+p2b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('beta_1_3_6_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_6_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_6_2_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_6_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_6_2_1',5,MA_ERR)
      IF ((h6b .le. h8b) .and. (p5b .lt. p2b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_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),
     &(p2b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p2b_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+p2b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h6b .le. h8b) .and. (p2b .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) * (p2b_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) * (p2b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p5b_2,p2b_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+p2b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF ((h8b .lt. h6b) .and. (p5b .lt. p2b)) THEN
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_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),
     &(p2b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p2b_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+p2b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h8b .lt. h6b) .and. (p2b .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) * (p2b_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) * (p2b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p5b_2,p2b_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+p2b-1),int_mb(k_range+p5b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_6_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('beta_1_3_6_2_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_6_2_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('
     &beta_1_3_6_2_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p2b-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),(p2b -
     & noab - 1 + nvab * (h8b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_6_2_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_6_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 beta_1_3_6_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h11 )_vtrbtra + = 1/2 * Sum ( p2 ) * tra ( p2 p12 h10 h11 )_tra * i3 ( h8 p2 )_vtrb
      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 p12b
      INTEGER h8b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p2b
      INTEGER p12b_1
      INTEGER p2b_1
      INTEGER h10b_1
      INTEGER h11b_1
      INTEGER h8b_2
      INTEGER p2b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO p12b = noab+1,noab+nvab
      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+h8b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h8b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irre
     &p_trb,irrep_tra))) THEN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+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('beta_1_3_6_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p2b = noab+1,noab+nvab
      IF (int_mb(k_spin+p12b-1)+int_mb(k_spin+p2b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),ieor(int_mb(k_sym+p2b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. irrep_tra) THEN
      CALL TCE_RESTRICTED_4(p12b,p2b,h10b,h11b,p12b_1,p2b_1,h10b_1,h11b_
     &1)
      CALL TCE_RESTRICTED_2(h8b,p2b,h8b_2,p2b_2)
      dim_common = int_mb(k_range+p2b-1)
      dima_sort = int_mb(k_range+p12b-1) * int_mb(k_range+h10b-1) * int_
     &mb(k_range+h11b-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('beta_1_3_6_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_6_2',2,MA_ERR)
      IF ((p2b .le. p12b)) 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 * (p12b_1 - noab - 1 + nvab * (p
     &2b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b
     &-1),4,3,2,1,1.0d0)
      END IF
      IF ((p12b .lt. p2b)) 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 * (p2b_1 - noab - 1 + nvab * (p1
     &2b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+p2b-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('beta_1_3_6_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_6_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_6_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_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+p2b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_6_2',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_6_2',8,MA_
     &ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_3_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+h11b-1),int_mb(k_range+h10b-1),int_mb(k_range+p12b
     &-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 * (p12b - noab - 1 + nvab * (h8b - 1
     &)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_6_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_6_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 beta_1_3_6(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h11 )_vtrbtratrc + = -1 * Sum ( h8 ) * trc ( p9 h8 )_trc * i2 ( h8 p12 h10 h11 )_vtrbtra
      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 p12b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p9b_1
      INTEGER h8b_1
      INTEGER p12b_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 p9b = noab+1,noab+nvab
      DO p12b = 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+p9b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irre
     &p_trb,ieor(irrep_tra,irrep_trc)))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+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('beta_1_3_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_trc) 
     &THEN
      CALL TCE_RESTRICTED_2(p9b,h8b,p9b_1,h8b_1)
      CALL TCE_RESTRICTED_4(p12b,h8b,h10b,h11b,p12b_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+p12b-1) * int_mb(k_range+h10b-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('beta_1_3_6',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_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('beta_1_3_6',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_6',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_6',5,MA_ERR)
      IF ((h8b .le. p12b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (p12b_2 - noab - 1 + nvab * (h
     &8b_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+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b
     &-1),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_6',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_6',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_3_6',9,MA_ERR)
      IF ((p9b .le. p12b)) THEN
      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+p12b-1),int_mb(k_range+p9b
     &-1),4,3,2,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 * (p12b - noab - 1 + nvab * (p9b - n
     &oab - 1)))))
      END IF
      IF ((p12b .le. p9b)) THEN
      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+p12b-1),int_mb(k_range+p9b
     &-1),3,4,2,1,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p9b - noab - 1 + nvab * (p12b - n
     &oab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_6',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_6',11,MA_E
     &RR)
      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 beta_1_3_7_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h4 p5 )_vtrc + = 1 * Sum ( h8 p7 ) * trc ( p7 h8 )_trc * v ( h4 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 h4b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h8b
      INTEGER p7b_1
      INTEGER h8b_1
      INTEGER h4b_2
      INTEGER h8b_2
      INTEGER p5b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h4b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p5b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p5b-1)) .eq. ieor(irrep_
     &v,irrep_trc)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_7_1_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO h8b = 1,noab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h8b-1)) .eq. irrep_trc) 
     &THEN
      CALL TCE_RESTRICTED_2(p7b,h8b,p7b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h4b,h8b,p5b,p7b,h4b_2,h8b_2,p5b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+h8b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+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('beta_1_3_7_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_7_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_7_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_7_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_7_1_1',5,MA_ERR)
      IF ((h8b .lt. h4b) .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) * (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),
     &(p5b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p5b_2,p7b_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+p7b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h8b .lt. h4b) .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) * (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),
     &(p7b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))),p7b_2,p5b_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+p5b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h4b .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) * (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) * (p7b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p5b_2,p7b_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+p7b-1),int_mb(k_range+p5b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h4b .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) * (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) * (p5b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p7b_2,p5b_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+p5b-1),int_mb(k_range+p7b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_7_1_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('beta_1_3_7_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_7_1_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('
     &beta_1_3_7_1_1',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+h4b-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 * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_7_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_7_1_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 beta_1_3_7_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h11 )_vtrctrb + = 1 * Sum ( p5 ) * trb ( p5 h11 )_trb * i3 ( h4 p5 )_vtrc
      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 h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h11b_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 h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h11b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h11b-1)) .eq. ieor(irrep
     &_v,ieor(irrep_trc,irrep_trb))) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_7_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h11b,p5b_1,h11b_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+h11b-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('beta_1_3_7_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_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 * (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('beta_1_3_7_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_7_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_7_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('beta_1_3_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('beta_1_3_7_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_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('
     &beta_1_3_7_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+h11b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_7_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_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
c done till here 2/7/2014 11:30am
      SUBROUTINE beta_1_3_7_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h4 p7 )_vtrb + = 1 * Sum ( h6 p5 ) * trb ( p5 h6 )_trb * v ( h4 h6 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 h4b
      INTEGER p7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h6b
      INTEGER p5b_1
      INTEGER h6b_1
      INTEGER h4b_2
      INTEGER h6b_2
      INTEGER 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 h4b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p7b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p7b-1)) .eq. ieor(irrep_
     &v,irrep_trb)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_7_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO h6b = 1,noab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h6b-1)) .eq. irrep_trb) 
     &THEN
      CALL TCE_RESTRICTED_2(p5b,h6b,p5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h4b,h6b,p7b,p5b,h4b_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+h4b-1) * int_mb(k_range+p7b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('beta_1_3_7_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_7_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h6b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_7_2_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_7_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_7_2_1',5,MA_ERR)
      IF ((h6b .lt. h4b) .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) * (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) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p7b_2,p5b_2,h4b_2,h6b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h6b .lt. h4b) .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) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p5b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))),p5b_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+p5b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF ((h4b .le. 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) * (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) * (p5b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p7b_2,p5b_2,h6b_2,h4b_2)
      end if
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF ((h4b .le. 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) * (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) * (p7b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))),p5b_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+p5b-1)
     &,3,1,2,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_7_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('beta_1_3_7_2_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_7_2_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('
     &beta_1_3_7_2_1',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+h4b-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 * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_7_2_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_7_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 beta_1_3_7_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h11 )_vtrbtrc + = -1 * Sum ( p7 ) * trc ( p7 h11 )_trc * i3 ( h4 p7 )_vtrb
      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 h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h11b_1
      INTEGER h4b_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 h4b = 1,noab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h11b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h11b-1)) .eq. ieor(irrep
     &_v,ieor(irrep_trb,irrep_trc))) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_7_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+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h11b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p7b,h11b,p7b_1,h11b_1)
      CALL TCE_RESTRICTED_2(h4b,p7b,h4b_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+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('beta_1_3_7_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_7_2',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('beta_1_3_7_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_7_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_7_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 * (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+p7b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_7_2',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_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('
     &beta_1_3_7_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+h11b-1),1,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_7_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_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
c done till here
      SUBROUTINE beta_1_3_7(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h11 )_vtrctrbtra + = -1/2 * Sum ( h4 ) * tra ( p9 p12 h4 h10 )_tra * i2 ( h4 h11 )_vtrctrb
      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 p12b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p9b_1
      INTEGER p12b_1
      INTEGER h10b_1
      INTEGER h4b_1
      INTEGER h4b_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 p9b = noab+1,noab+nvab
      DO p12b = p9b,noab+nvab
      DO h10b = 1,noab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irre
     &p_trc,ieor(irrep_trb,irrep_tra)))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+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('beta_1_3_7',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)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h4b-1)))) .eq. irrep_tra) THEN
      CALL TCE_RESTRICTED_4(p9b,p12b,h10b,h4b,p9b_1,p12b_1,h10b_1,h4b_1)
      CALL TCE_RESTRICTED_2(h4b,h11b,h4b_2,h11b_2)
      dim_common = int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+p12b-1) * int_m
     &b(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = 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('beta_1_3_7',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_7',2,MA_ERR)
      IF ((h4b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h4b_1 - 1 + noab * (p12b_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+p12b-1),int_mb(k_range+h4b-1),int_mb(k_range+h10b-
     &1),4,2,1,3,1.0d0)
      END IF
      IF ((h10b .lt. h4b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p12b_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+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+h4b-
     &1),3,2,1,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_7',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_7',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_7',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &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+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_7',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_7',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_3_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+h10b-1),int_mb(k_range+p12b-1),int_mb(k_range+p9b
     &-1),4,3,2,1,-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 * (p12b - noab - 1 + nvab * (p9b - n
     &oab - 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+h10b-1),int_mb(k_range+p12b-1),int_mb(k_range+p9b
     &-1),4,3,1,2,1.0d0/4.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h11b - 1 + noab * (p12b - noab - 1 + nvab * (p9b - n
     &oab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_7',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_7',11,MA_E
     &RR)
      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 beta_1_3_8_1_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i4 ( h2 h4 h11 p5 )_vtrc + = 1 * Sum ( p7 ) * trc ( p7 h11 )_trc * v ( h2 h4 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 h2b
      INTEGER h4b
      INTEGER h11b
      INTEGER p5b
      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 p5b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h4b = h2b,noab
      DO h11b = 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+h11b-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
     &11b-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+h11b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_v,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_8_1_1_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_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p7b,h11b,p7b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p5b,p7b,h2b_2,h4b_2,p5b_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+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('beta_1_3_8_1_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_8_1_1_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('beta_1_3_8_1_1_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_8_1_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_8_1_1_1',5,MA_ERR)
      IF ((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) * (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),
     &(p5b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p5b_2,p7b_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+p7b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((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) * (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),
     &(p7b_2
     & - 1 + (noab+nvab) * (p5b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h2b_2 - 1)))),p7b_2,p5b_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+p5b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_8_1_1_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('beta_1_3_8_1_1_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_8_1_1_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('
     &beta_1_3_8_1_1_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+h11b-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 * (h11b - 1 + noab * (h4b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_8_1_1_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_8_1_1_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 beta_1_3_8_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h11 )_vtrctrb + = 1 * Sum ( p5 ) * trb ( p5 h10 )_trb * i4 ( h2 h4 h11 p5 )_vtrc
      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 h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h11b_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 = h2b,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+h4b-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+h4b-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+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irrep
     &_trc,irrep_trb))) 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+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3_8_1_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h10b,p5b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h11b,p5b,h2b_2,h4b_2,h11b_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+h4b-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('beta_1_3_8_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_8_1_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('beta_1_3_8_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_8_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_8_1_1',5,MA_ERR)
      IF ((h11b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_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+p5b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_8_1_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('beta_1_3_8_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_8_1_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('
     &beta_1_3_8_1_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+h4b-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 * (h4b - 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+h4b-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 * (h4b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_8_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_8_1_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 beta_1_3_8_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h10 h11 )_vtrctrbtra + = 1 * Sum ( h4 ) * tra ( p9 h4 )_tra * i3 ( h2 h4 h10 h11 )_vtrctrb
      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 h2b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p9b_1
      INTEGER h4b_1
      INTEGER h2b_2
      INTEGER h4b_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 p9b = noab+1,noab+nvab
      DO h2b = 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+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
     &_trc,ieor(irrep_trb,irrep_tra)))) 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('beta_1_3_8_1',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_tra) 
     &THEN
      CALL TCE_RESTRICTED_2(p9b,h4b,p9b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h10b,h11b,h2b_2,h4b_2,h10b_2,h11b_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+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('beta_1_3_8_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_8_1',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('beta_1_3_8_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_8_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_8_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),(h11b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,-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),(h11b_
     &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+h11b-
     &1),4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_8_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_8_1',8,MA_
     &ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_3_8_1',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('beta_1_3_8_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_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 beta_1_3_8(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h11 )_vtrctrbtrat + = 1/2 * Sum ( h2 ) * t ( p12 h2 )_t * i2 ( h2 p9 h10 h11 )_vtrctrbtra
      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 p12b
      INTEGER p9b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h2b
      INTEGER p12b_1
      INTEGER h2b_1
      INTEGER p9b_2
      INTEGER h2b_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 p12b = noab+1,noab+nvab
      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+p9b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_v,ieor(irre
     &p_trc,ieor(irrep_trb,ieor(irrep_tra,irrep_t))))) THEN
      dimc = int_mb(k_range+p9b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+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('beta_1_3_8',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h2b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h2b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h2b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p12b,h2b,p12b_1,h2b_1)
      CALL TCE_RESTRICTED_4(p9b,h2b,h10b,h11b,p9b_2,h2b_2,h10b_2,h11b_2)
      dim_common = int_mb(k_range+h2b-1)
      dima_sort = int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p9b-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('beta_1_3_8',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3_8',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h2b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h2b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3_8',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3_8',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3_8',5,MA_ERR)
      IF ((h2b .le. p9b)) THEN
      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),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3_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('beta_1_3_8',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3_8',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_3_8',9,MA_ERR)
      IF ((p9b .le. p12b)) THEN
      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+p9b-1),int_mb(k_range+p12b
     &-1),3,4,2,1,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 * (p12b - noab - 1 + nvab * (p9b - n
     &oab - 1)))))
      END IF
      IF ((p12b .le. p9b)) THEN
      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+p9b-1),int_mb(k_range+p12b
     &-1),4,3,2,1,-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 * (p12b - n
     &oab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3_8',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3_8',11,MA_E
     &RR)
      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 beta_1_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( )_vtrctrbtray + = -1 * Sum ( p12 p9 h10 h11 ) * y ( h10 h11 p9 p12 )_y * i1 ( p9 p12 h10 h11 )_vtrctrbtra
      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 dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h10b
      INTEGER h11b
      INTEGER p9b
      INTEGER p12b
      INTEGER h10b_1
      INTEGER h11b_1
      INTEGER p9b_1
      INTEGER p12b_1
      INTEGER p9b_2
      INTEGER p12b_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 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)
      IF (next.eq.count) THEN
      IF (0 .eq. ieor(irrep_v,ieor(irrep_trc,ieor(irrep_trb,ieor(irrep_t
     &ra,irrep_y))))) THEN
      dimc = 1
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_3',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
      DO p12b = p9b,noab+nvab
      IF (int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1) .eq. int_mb(k_spin
     &+p9b-1)+int_mb(k_spin+p12b-1)) THEN
      IF (ieor(int_mb(k_sym+h10b-1),ieor(int_mb(k_sym+h11b-1),ieor(int_m
     &b(k_sym+p9b-1),int_mb(k_sym+p12b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h10b,h11b,p9b,p12b,h10b_1,h11b_1,p9b_1,p12b_
     &1)
      CALL TCE_RESTRICTED_4(p9b,p12b,h10b,h11b,p9b_2,p12b_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) * int_mb(k_range+p12b-1)
      dima_sort = 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('beta_1_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p12b_
     &1 - noab - 1 + nvab * (p9b_1 - noab - 1 + nvab * (h11b_1 - 1 + noa
     &b * (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+p12b
     &-1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_3',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_3',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 * (p12b_2 - noab - 1 + nvab * (p
     &9b_2 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b
     &-1),2,1,4,3,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_3',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
      nsubp(1) = 1
      nsubp(2) = 1
      isubp = 1
      IF (p9b .eq. p12b) THEN
      nsubp(isubp) = nsubp(isubp) + 1
      ELSE
      isubp = isubp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,4.0d0/FACTORIAL(
     &nsuperh(1))/FACTORIAL(nsuperh(2))/FACTORIAL(nsubp(1))/FACTORIAL(ns
     &ubp(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('beta_1_3',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_3',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_3',9,MA_ERR)
      CALL TCE_SORT_0(dbl_mb(k_c_sort),dbl_mb(k_c),-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),0)
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_3',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_3',11,MA_ERR
     &)
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE beta_1_4_1_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h13 )_ytrb + = -1 * Sum ( p3 p4 ) * trb ( p3 p4 h10 h13 )_trb * 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 h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h10b_1
      INTEGER h13b_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 = h2b,noab
      DO h10b = 1,noab
      DO h13b = 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+h13b-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+h13b-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+h13b-1)))) .eq. ieor(irrep_y,irrep_trb)
     &) 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+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_1_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+h13b-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+h13b-1)))) .eq. irrep_trb) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h10b,h13b,p3b_1,p4b_1,h10b_1,h13b_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+h13b-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('beta_1_4_1_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_1_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 * (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)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_1_1_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('beta_1_4_1_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_1_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('
     &beta_1_4_1_1_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+h13b-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),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_1_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 beta_1_4_1_1_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i4 ( h2 h8 h13 p3 )_ytrb + = 1 * Sum ( p5 ) * trb ( p5 h13 )_trb * 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 h13b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h13b_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 = h2b,noab
      DO h13b = 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+h13b-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
     &13b-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+h13b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_trb))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h13b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_1_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+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h13b,p5b_1,h13b_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+h13b-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('beta_1_4_1_1_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_1_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1_1_2_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_1_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_1_2_1',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 * (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 ((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('beta_1_4_1_1_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('beta_1_4_1_1_2_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_1_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('
     &beta_1_4_1_1_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+h13b-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 * (h13b - 1 + noab * (h8b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_1_2_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_1_2_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 beta_1_4_1_1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h13 )_ytrbt + = -4 * Sum ( p3 ) * t ( p3 h10 )_t * i4 ( h2 h8 h13 p3 )_ytrb
      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 h13b
      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 h13b_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 = h2b,noab
      DO h10b = 1,noab
      DO h13b = 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+h13b-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+h13b-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+h13b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trb,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+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_1_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,h8b,h13b,p3b,h2b_2,h8b_2,h13b_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+h13b-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('beta_1_4_1_1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_1_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('beta_1_4_1_1_2',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_1_2',5,MA_ERR)
      IF ((h13b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h13b_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+h13b-1),int_mb(k_range+p3b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_1_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('beta_1_4_1_1_2',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_1_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('
     &beta_1_4_1_1_2',9,MA_ERR)
      IF ((h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h8b-1),int_mb(k_range+h2b-1),int_mb(k_range+h10b-
     &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),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h13b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h8b-1),int_mb(k_range+h2b-1),int_mb(k_range+h10b-
     &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),(h10b 
     &- 1 + noab * (h13b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_1_2',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_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 beta_1_4_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h13 )_ytrbtrc + = 1 * Sum ( h8 ) * trc ( p12 h8 )_trc * i3 ( h2 h8 h10 h13 )_ytrb
      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 p12b
      INTEGER h2b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p12b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER h10b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_trb,irrep_trc))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h8b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h8b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p12b,h8b,p12b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h10b,h13b,h2b_2,h8b_2,h10b_2,h13b_2)
      dim_common = int_mb(k_range+h8b-1)
      dima_sort = int_mb(k_range+p12b-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+h13b-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('beta_1_4_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h8b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_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),(h13b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h13b-
     &1),4,3,2,1,-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),(h13b_
     &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+h13b-
     &1),4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_1_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('beta_1_4_1_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_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('
     &beta_1_4_1_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+h2b-1),int_mb(k_range+p12b
     &-1),3,4,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (h2b - 1
     &)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_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 beta_1_4_1_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h5 h13 p3 )_ytrc + = 1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h2 h5 p3 p7 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h5b
      INTEGER h13b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h13b_1
      INTEGER h2b_2
      INTEGER h5b_2
      INTEGER p3b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h5b = h2b,noab
      DO h13b = 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+h13b-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
     &13b-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+h13b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h13b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_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+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p7b,h13b,p7b_1,h13b_1)
      CALL TCE_RESTRICTED_4(h2b,h5b,p3b,p7b,h2b_2,h5b_2,p3b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h13b-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('beta_1_4_1_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1_2_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_2_1',5,MA_ERR)
      IF ((p7b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h5b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p7b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p3b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h5b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_1_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('beta_1_4_1_2_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_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('
     &beta_1_4_1_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+h5b-1),int_mb(k_range+h2b-1),int_mb(k_range+h13b-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 * (h13b - 1 + noab * (h5b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_2_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_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 beta_1_4_1_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h13 )_ytrctrb + = 4 * Sum ( h5 p3 ) * trb ( p3 p12 h5 h10 )_trb * i3 ( h2 h5 h13 p3 )_ytrc
      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 p12b
      INTEGER h2b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h5b
      INTEGER p12b_1
      INTEGER p3b_1
      INTEGER h10b_1
      INTEGER h5b_1
      INTEGER h2b_2
      INTEGER h5b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h13b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_trc,irrep_trb))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO h5b = 1,noab
      IF (int_mb(k_spin+p12b-1)+int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h5b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),ieor(int_mb(k_sym+p3b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h5b-1)))) .eq. irrep_trb) THEN
      CALL TCE_RESTRICTED_4(p12b,p3b,h10b,h5b,p12b_1,p3b_1,h10b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h2b,h5b,h13b,p3b,h2b_2,h5b_2,h13b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1) * int_mb(k_range+h5b-1)
      dima_sort = int_mb(k_range+p12b-1) * int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-1) * int_mb(k_range+h13b-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('beta_1_4_1_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_2',2,MA_ERR)
      IF ((p3b .le. p12b) .and. (h5b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h5b_1 - 1 + noab * (p12b_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+p12b-1),int_mb(k_range+h5b-1),int_mb(k_range+h10b-
     &1),4,2,3,1,1.0d0)
      END IF
      IF ((p3b .le. p12b) .and. (h10b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p12b_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+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+h5b-
     &1),3,2,4,1,-1.0d0)
      END IF
      IF ((p12b .lt. p3b) .and. (h5b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h5b_1 - 1 + noab * (p3b_1 - noab - 1 + nvab * (p12
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+p3b-1),int_mb(k_range+h5b-1),int_mb(k_range+h10b-
     &1),4,1,3,2,-1.0d0)
      END IF
      IF ((p12b .lt. p3b) .and. (h10b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p3b_1 - noab - 1 + nvab * (p12
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+p3b-1),int_mb(k_range+h10b-1),int_mb(k_range+h5b-
     &1),3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_2',5,MA_ERR)
      IF ((h5b .lt. h2b) .and. (h13b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h13b_2 - 1 + noab * (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+h13b-1),int_mb(k_range+p3b-1
     &),3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h5b) .and. (h13b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h13b_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+h13b-1),int_mb(k_range+p3b-1
     &),3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_1_2',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_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('
     &beta_1_4_1_2',9,MA_ERR)
      IF ((h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+h10b-1),int_mb(k_range+p12b
     &-1),2,4,3,1,2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF ((h13b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+h10b-1),int_mb(k_range+p12b
     &-1),2,4,1,3,-2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h13b - 1 + noab * (p12b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_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 beta_1_4_1_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h1 h2 h10 h13 )_ytrc + = 1 * Sum ( p5 p6 ) * trc ( p5 p6 h10 h13 )_trc * y ( h1 h2 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 h1b
      INTEGER h2b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p6b
      INTEGER p5b_1
      INTEGER p6b_1
      INTEGER h10b_1
      INTEGER h13b_1
      INTEGER h1b_2
      INTEGER h2b_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 h1b = 1,noab
      DO h2b = h1b,noab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h1b-1)+int_mb(k_spin+h2b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h1b-1)+int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h1b-1),ieor(int_mb(k_sym+h2b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,irrep_trc)
     &) THEN
      dimc = int_mb(k_range+h1b-1) * int_mb(k_range+h2b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_3_1',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+h13b-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+h13b-1)))) .eq. irrep_trc) THEN
      CALL TCE_RESTRICTED_4(p5b,p6b,h10b,h13b,p5b_1,p6b_1,h10b_1,h13b_1)
      CALL TCE_RESTRICTED_4(h1b,h2b,p5b,p6b,h1b_2,h2b_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+h13b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h1b-1) * 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('beta_1_4_1_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_3_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1_3_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_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 * (p5b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (h1b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h1b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p5b-1),int_mb(k_range+p6b-1)
     &,2,1,4,3,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_1_3_1',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('beta_1_4_1_3_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_3_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('
     &beta_1_4_1_3_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+h1b-1),int_mb(k_range+h13b-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),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (h2b - 1 + noab * (h1b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_3_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_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 beta_1_4_1_3_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i4 ( h1 h2 h13 p3 )_ytrc + = -1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h1 h2 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 h1b
      INTEGER h2b
      INTEGER h13b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h13b_1
      INTEGER h1b_2
      INTEGER h2b_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 h1b = 1,noab
      DO h2b = h1b,noab
      DO h13b = 1,noab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h1b-1)+int_mb(k_spin+h2b-1
     &)+int_mb(k_spin+h13b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h1b-1)+int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h
     &13b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h1b-1),ieor(int_mb(k_sym+h2b-1),ieor(int_mb(
     &k_sym+h13b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h1b-1) * int_mb(k_range+h2b-1) * int_mb(k_ra
     &nge+h13b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_3_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+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p7b,h13b,p7b_1,h13b_1)
      CALL TCE_RESTRICTED_4(h1b,h2b,p3b,p7b,h1b_2,h2b_2,p3b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h13b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h1b-1) * 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('beta_1_4_1_3_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_3_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1_3_2_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_3_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_3_2_1',5,MA_ERR)
      IF ((p7b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (h1b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h1b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+p7b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p3b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h2b_2 - 1 + noab 
     &* (h1b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h1b-1)
     &,int_mb(k_range+h2b-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('beta_1_4_1_3_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('beta_1_4_1_3_2_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_3_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('
     &beta_1_4_1_3_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+h2b-1),int_mb(k_range+h1b-1),int_mb(k_range+h13b-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 * (h13b - 1 + noab * (h2b - 1 + noab * (h1b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_3_2_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_3_2_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 beta_1_4_1_3_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h1 h2 h10 h13 )_ytrct + = -4 * Sum ( p3 ) * t ( p3 h10 )_t * i4 ( h1 h2 h13 p3 )_ytrc
      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 h1b
      INTEGER h2b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h10b_1
      INTEGER h1b_2
      INTEGER h2b_2
      INTEGER h13b_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 h1b = 1,noab
      DO h2b = h1b,noab
      DO h10b = 1,noab
      DO h13b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h1b-1)+int_mb(k_spin+h2b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h1b-1)+int_mb(k_spin+h2b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h1b-1),ieor(int_mb(k_sym+h2b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trc,irrep_t))) THEN
      dimc = int_mb(k_range+h1b-1) * int_mb(k_range+h2b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_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(h1b,h2b,h13b,p3b,h1b_2,h2b_2,h13b_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+h1b-1) * int_mb(k_range+h2b-1) * int_mb
     &(k_range+h13b-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('beta_1_4_1_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_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('beta_1_4_1_3_2',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_3_2',5,MA_ERR)
      IF ((h13b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h13b_2 - 1 + noab * (h2b_2 - 1 + noab * (h1b
     &_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h1b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h13b-1),int_mb(k_range+p3b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_1_3_2',6,MA_ERR
     &)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_4_1_3_2',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_3_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('
     &beta_1_4_1_3_2',9,MA_ERR)
      IF ((h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+h1b-1),int_mb(k_range+h10b-
     &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),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (h2b - 1 + noab * (h1b - 1)))))
      END IF
      IF ((h13b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h2b-1),int_mb(k_range+h1b-1),int_mb(k_range+h10b-
     &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),(h10b 
     &- 1 + noab * (h13b - 1 + noab * (h2b - 1 + noab * (h1b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_3_2',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_3_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 beta_1_4_1_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h13 )_ytrctrb + = 1 * Sum ( h1 ) * trb ( p12 h1 )_trb * i3 ( h1 h2 h10 h13 )_ytrc
      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 p12b
      INTEGER h2b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h1b
      INTEGER p12b_1
      INTEGER h1b_1
      INTEGER h2b_2
      INTEGER h1b_2
      INTEGER h10b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_trc,irrep_trb))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h1b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h1b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h1b-1)) .eq. irrep_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p12b,h1b,p12b_1,h1b_1)
      CALL TCE_RESTRICTED_4(h2b,h1b,h10b,h13b,h2b_2,h1b_2,h10b_2,h13b_2)
      dim_common = int_mb(k_range+h1b-1)
      dima_sort = int_mb(k_range+p12b-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+h13b-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('beta_1_4_1_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h1b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h1b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1_3',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_3',5,MA_ERR)
      IF ((h1b .le. h2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h13b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (h2b_2 - 1 + noab * (h1b_2 - 1
     &)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h1b-1)
     &,int_mb(k_range+h2b-1),int_mb(k_range+h10b-1),int_mb(k_range+h13b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF ((h2b .lt. h1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h13b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (h1b_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+h1b-1),int_mb(k_range+h10b-1),int_mb(k_range+h13b-
     &1),4,3,1,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_1_3',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_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('
     &beta_1_4_1_3',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+h2b-1),int_mb(k_range+p12b
     &-1),3,4,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (h2b - 1
     &)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_3',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_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 beta_1_4_1_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i3 ( h2 h7 h10 p5 )_ytrb + = 1 * Sum ( p3 ) * trb ( p3 h10 )_trb * y ( h2 h7 p3 p5 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h7b
      INTEGER h10b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h7b_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 h2b = 1,noab
      DO h7b = h2b,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+h7b-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+h7b-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+h7b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_trb))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h7b-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('beta_1_4_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p3b,h10b,p3b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,p5b,p3b,h2b_2,h7b_2,p5b_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+h7b-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('beta_1_4_1_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_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('beta_1_4_1_4_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_4_1',5,MA_ERR)
      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 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p3b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,1.0d0)
      END IF
      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 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h7b-1),int_mb(k_range+p5b-1),int_mb(k_range+p3b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_1_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('beta_1_4_1_4_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_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('
     &beta_1_4_1_4_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+h7b-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 * (h7b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_4_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_4_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 beta_1_4_1_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h13 )_ytrbtrc + = 4 * Sum ( h7 p5 ) * trc ( p5 p12 h7 h13 )_trc * i3 ( h2 h7 h10 p5 )_ytrb
      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 p12b
      INTEGER h2b
      INTEGER h13b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h7b
      INTEGER p12b_1
      INTEGER p5b_1
      INTEGER h13b_1
      INTEGER h7b_1
      INTEGER h2b_2
      INTEGER h7b_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 p12b = noab+1,noab+nvab
      DO h2b = 1,noab
      DO h13b = 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+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_trb,irrep_trc))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO h7b = 1,noab
      IF (int_mb(k_spin+p12b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+
     &h13b-1)+int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb
     &(k_sym+h13b-1),int_mb(k_sym+h7b-1)))) .eq. irrep_trc) THEN
      CALL TCE_RESTRICTED_4(p12b,p5b,h13b,h7b,p12b_1,p5b_1,h13b_1,h7b_1)
      CALL TCE_RESTRICTED_4(h2b,h7b,h10b,p5b,h2b_2,h7b_2,h10b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+h7b-1)
      dima_sort = int_mb(k_range+p12b-1) * int_mb(k_range+h13b-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('beta_1_4_1_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_4',2,MA_ERR)
      IF ((p5b .le. p12b) .and. (h7b .le. h13b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &1 - 1 + noab * (h7b_1 - 1 + noab * (p12b_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+p12b-1),int_mb(k_range+h7b-1),int_mb(k_range+h13b-
     &1),4,2,3,1,1.0d0)
      END IF
      IF ((p5b .le. p12b) .and. (h13b .lt. h7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (h13b_1 - 1 + noab * (p12b_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+p12b-1),int_mb(k_range+h13b-1),int_mb(k_range+h7b-
     &1),3,2,4,1,-1.0d0)
      END IF
      IF ((p12b .lt. p5b) .and. (h7b .le. h13b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &1 - 1 + noab * (h7b_1 - 1 + noab * (p5b_1 - noab - 1 + nvab * (p12
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+p5b-1),int_mb(k_range+h7b-1),int_mb(k_range+h13b-
     &1),4,1,3,2,-1.0d0)
      END IF
      IF ((p12b .lt. p5b) .and. (h13b .lt. h7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (h13b_1 - 1 + noab * (p5b_1 - noab - 1 + nvab * (p12
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+p5b-1),int_mb(k_range+h13b-1),int_mb(k_range+h7b-
     &1),3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1_4',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_4',5,MA_ERR)
      IF ((h7b .lt. h2b) .and. (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 * (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+h10b-1),int_mb(k_range+p5b-1
     &),3,2,1,4,-1.0d0)
      END IF
      IF ((h2b .le. h7b) .and. (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 * (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+h10b-1),int_mb(k_range+p5b-1
     &),3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_1_4',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_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('
     &beta_1_4_1_4',9,MA_ERR)
      IF ((h10b .le. h13b)) 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+h13b-1),int_mb(k_range+p12b
     &-1),2,4,1,3,2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF ((h13b .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+h13b-1),int_mb(k_range+p12b
     &-1),2,4,3,1,-2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h13b - 1 + noab * (p12b - noab - 1 + nvab * (h2b - 1
     &)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_4',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_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 beta_1_4_1_5_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i4 ( h2 h4 h13 p5 )_ytrc + = 1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h2 h4 p5 p7 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h4b
      INTEGER h13b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h13b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER p5b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h4b = h2b,noab
      DO h13b = 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+h13b-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
     &13b-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+h13b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h13b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_5_1_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+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p7b,h13b,p7b_1,h13b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p5b,p7b,h2b_2,h4b_2,p5b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h13b-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('beta_1_4_1_5_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_5_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1_5_1_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_5_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_5_1_1',5,MA_ERR)
      IF ((p7b .lt. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h4b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p7b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p5b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h4b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_1_5_1_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('beta_1_4_1_5_1_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_5_1_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('
     &beta_1_4_1_5_1_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+h13b-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 * (h13b - 1 + noab * (h4b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_5_1_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_5_1_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 beta_1_4_1_5_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h13 )_ytrctrb + = 1 * Sum ( p5 ) * trb ( p5 h10 )_trb * i4 ( h2 h4 h13 p5 )_ytrc
      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 h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h13b_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 = h2b,noab
      DO h10b = 1,noab
      DO h13b = 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+h13b-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+h13b-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+h13b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trc,irrep_trb))) 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+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_5_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h10b,p5b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h13b,p5b,h2b_2,h4b_2,h13b_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+h4b-1) * int_mb
     &(k_range+h13b-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('beta_1_4_1_5_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_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 * (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('beta_1_4_1_5_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_5_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_5_1',5,MA_ERR)
      IF ((h13b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (h13b_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+h13b-1),int_mb(k_range+p5b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_1_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('beta_1_4_1_5_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_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('
     &beta_1_4_1_5_1',9,MA_ERR)
      IF ((h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-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/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h13b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h4b-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 * (h13b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_5_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_5_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 beta_1_4_1_5(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h13 )_ytrctrbt + = -2 * Sum ( h4 ) * t ( p12 h4 )_t * i3 ( h2 h4 h10 h13 )_ytrctrb
      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 p12b
      INTEGER h2b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p12b_1
      INTEGER h4b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h10b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_trc,ieor(irrep_trb,irrep_t)))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h4b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p12b,h4b,p12b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h10b,h13b,h2b_2,h4b_2,h10b_2,h13b_2)
      dim_common = int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p12b-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+h13b-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('beta_1_4_1_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1_5',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1_5',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1_5',5,MA_ERR)
      IF ((h4b .lt. h2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h13b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h13b-
     &1),4,3,2,1,-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),(h13b_
     &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+h13b-
     &1),4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_1_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('beta_1_4_1_5',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1_5',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('
     &beta_1_4_1_5',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+h2b-1),int_mb(k_range+p12b
     &-1),3,4,2,1,-2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (h2b - 1
     &)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1_5',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1_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 beta_1_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p11 p12 h10 h13 )_ytrbtrctra + = 1 * Sum ( h2 ) * tra ( p11 h2 )_tra * i2 ( h2 p12 h10 h13 )_ytrbtrc
      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 p11b
      INTEGER p12b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h2b
      INTEGER p11b_1
      INTEGER h2b_1
      INTEGER p12b_2
      INTEGER h2b_2
      INTEGER h10b_2
      INTEGER h13b_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 p11b = noab+1,noab+nvab
      DO p12b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b
     &-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin
     &+h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_m
     &b(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irr
     &ep_trb,ieor(irrep_trc,irrep_tra)))) THEN
      dimc = int_mb(k_range+p11b-1) * int_mb(k_range+p12b-1) * int_mb(k_
     &range+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h2b = 1,noab
      IF (int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+h2b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),int_mb(k_sym+h2b-1)) .eq. irrep_tra)
     & THEN
      CALL TCE_RESTRICTED_2(p11b,h2b,p11b_1,h2b_1)
      CALL TCE_RESTRICTED_4(p12b,h2b,h10b,h13b,p12b_2,h2b_2,h10b_2,h13b_
     &2)
      dim_common = int_mb(k_range+h2b-1)
      dima_sort = int_mb(k_range+p11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p12b-1) * int_mb(k_range+h10b-1) * int_
     &mb(k_range+h13b-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('beta_1_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h2b_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+h2b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_1',5,MA_ERR)
      IF ((h2b .le. p12b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h13b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (p12b_2 - noab - 1 + nvab * (h
     &2b_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+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+h13b
     &-1),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_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('beta_1_4_1',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_1',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_4_1',9,MA_ERR)
      IF ((p11b .le. p12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+p12b-1),int_mb(k_range+p11
     &b-1),4,3,2,1,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (p11b - 
     &noab - 1)))))
      END IF
      IF ((p12b .le. p11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+p12b-1),int_mb(k_range+p11
     &b-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),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (p12b - 
     &noab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_1',11,MA_E
     &RR)
      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 beta_1_4_2_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i3 ( h2 h10 )_ytrb + = -1 * Sum ( h5 p3 p4 ) * trb ( p3 p4 h5 h10 )_trb * 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 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 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 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_trb)) 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('beta_1_4_2_1_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
     &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_trb) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h10b,h5b,p3b_1,p4b_1,h10b_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+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('beta_1_4_2_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_2_1_1',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('beta_1_4_2_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_2_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_2_1_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('beta_1_4_2_1_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('beta_1_4_2_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_2_1_1',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('
     &beta_1_4_2_1_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('beta_1_4_2_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_2_1_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 beta_1_4_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p11 h10 )_ytrbtra + = 1 * Sum ( h2 ) * tra ( p11 h2 )_tra * i3 ( h2 h10 )_ytrb
      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 p11b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h2b
      INTEGER p11b_1
      INTEGER h2b_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 p11b = noab+1,noab+nvab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p11b-1)+int_mb(k_spin+h10b
     &-1).ne.4)) THEN
      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. ieor(irre
     &p_y,ieor(irrep_trb,irrep_tra))) THEN
      dimc = int_mb(k_range+p11b-1) * int_mb(k_range+h10b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h2b = 1,noab
      IF (int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+h2b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),int_mb(k_sym+h2b-1)) .eq. irrep_tra)
     & THEN
      CALL TCE_RESTRICTED_2(p11b,h2b,p11b_1,h2b_1)
      CALL TCE_RESTRICTED_2(h2b,h10b,h2b_2,h10b_2)
      dim_common = int_mb(k_range+h2b-1)
      dima_sort = int_mb(k_range+p11b-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('beta_1_4_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h2b_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+h2b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_2_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_2_1',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('beta_1_4_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('beta_1_4_2_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_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('
     &beta_1_4_2_1',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+p11b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (p11b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_2_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_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 beta_1_4_2_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h3 h4 h10 p1 )_ytrb + = -1 * Sum ( p5 ) * trb ( p5 h10 )_trb * y ( h3 h4 p1 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 h3b
      INTEGER h4b
      INTEGER h10b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h10b_1
      INTEGER h3b_2
      INTEGER h4b_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 h3b = 1,noab
      DO h4b = h3b,noab
      DO h10b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h3b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      IF (int_mb(k_spin+h3b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h3b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_y,irrep_trb))
     & THEN
      dimc = int_mb(k_range+h3b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_2_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h10b,p5b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h3b,h4b,p1b,p5b,h3b_2,h4b_2,p1b_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+h3b-1) * 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('beta_1_4_2_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_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 * (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('beta_1_4_2_2_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_2_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_2_2_1',5,MA_ERR)
      IF ((p5b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h4b_2 - 1 + noab 
     &* (h3b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p5b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (h4b_2 - 1 + noab 
     &* (h3b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p1b-1),int_mb(k_range+p5b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_2_2_1',6,MA_ERR
     &)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_4_2_2_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_2_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('
     &beta_1_4_2_2_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+h4b-1),int_mb(k_range+h3b-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),(p1b -
     & noab - 1 + nvab * (h10b - 1 + noab * (h4b - 1 + noab * (h3b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_2_2_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_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 beta_1_4_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p11 h10 )_ytrbtra + = -1 * Sum ( h3 h4 p1 ) * tra ( p1 p11 h3 h4 )_tra * i3 ( h3 h4 h10 p1 )_ytrb
      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 p11b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p1b
      INTEGER h3b
      INTEGER h4b
      INTEGER p11b_1
      INTEGER p1b_1
      INTEGER h3b_1
      INTEGER h4b_1
      INTEGER h3b_2
      INTEGER h4b_2
      INTEGER h10b_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 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 p11b = noab+1,noab+nvab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p11b-1)+int_mb(k_spin+h10b
     &-1).ne.4)) THEN
      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. ieor(irre
     &p_y,ieor(irrep_trb,irrep_tra))) THEN
      dimc = int_mb(k_range+p11b-1) * int_mb(k_range+h10b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p1b = noab+1,noab+nvab
      DO h3b = 1,noab
      DO h4b = h3b,noab
      IF (int_mb(k_spin+p11b-1)+int_mb(k_spin+p1b-1) .eq. int_mb(k_spin+
     &h3b-1)+int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb
     &(k_sym+h3b-1),int_mb(k_sym+h4b-1)))) .eq. irrep_tra) THEN
      CALL TCE_RESTRICTED_4(p11b,p1b,h3b,h4b,p11b_1,p1b_1,h3b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h3b,h4b,h10b,p1b,h3b_2,h4b_2,h10b_2,p1b_2)
      dim_common = int_mb(k_range+p1b-1) * int_mb(k_range+h3b-1) * int_m
     &b(k_range+h4b-1)
      dima_sort = int_mb(k_range+p11b-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('beta_1_4_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_2_2',2,MA_ERR)
      IF ((p1b .le. p11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (h3b_1 - 1 + noab * (p11b_1 - noab - 1 + nvab * (p1b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p11b-1),int_mb(k_range+h3b-1),int_mb(k_range+h4b-1
     &),2,4,3,1,1.0d0)
      END IF
      IF ((p11b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (h3b_1 - 1 + noab * (p1b_1 - noab - 1 + nvab * (p11b
     &_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+p1b-1),int_mb(k_range+h3b-1),int_mb(k_range+h4b-1
     &),1,4,3,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_2_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_2_2',5,MA_ERR)
      IF ((h10b .le. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (h10b_2 - 1 + noab * (h4b_2 - 1 + noab * (h3b
     &_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h10b-1),int_mb(k_range+p1b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_2_2',6,MA_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h3b .eq. h4b) 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('beta_1_4_2_2',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_2_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('
     &beta_1_4_2_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+p11b-1),2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (p11b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_2_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_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 beta_1_4_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p11 p12 h10 h13 )_ytrbtratrc + = 2 * trc ( p12 h13 )_trc * i2 ( p11 h10 )_ytrbtra
      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 p12b
      INTEGER p11b
      INTEGER h13b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p12b_1
      INTEGER h13b_1
      INTEGER p11b_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 p12b = noab+1,noab+nvab
      DO p11b = noab+1,noab+nvab
      DO h13b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b
     &-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin
     &+h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_m
     &b(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irr
     &ep_trb,ieor(irrep_tra,irrep_trc)))) THEN
      dimc = int_mb(k_range+p11b-1) * int_mb(k_range+p12b-1) * int_mb(k_
     &range+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trc
     &) THEN
      CALL TCE_RESTRICTED_2(p12b,h13b,p12b_1,h13b_1)
      CALL TCE_RESTRICTED_2(p11b,h10b,p11b_2,h10b_2)
      dim_common = 1
      dima_sort = int_mb(k_range+p12b-1) * int_mb(k_range+h13b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p11b-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('beta_1_4_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &1 - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h10b_
     &2 - 1 + noab * (p11b_2 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p11b-1
     &),int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_2',6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_4_2',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_2',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_4_2',9,MA_ERR)
      IF ((p11b .le. p12b) .and. (h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+p11b-1),int_mb(k_range+h13b-1),int_mb(k_range+p12
     &b-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),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (p11b - 
     &noab - 1)))))
      END IF
      IF ((p11b .le. p12b) .and. (h13b .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+p11b-1),int_mb(k_range+h13b-1),int_mb(k_range+p12
     &b-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 * (h13b - 1 + noab * (p12b - noab - 1 + nvab * (p11b - 
     &noab - 1)))))
      END IF
      IF ((p12b .le. p11b) .and. (h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+p11b-1),int_mb(k_range+h13b-1),int_mb(k_range+p12
     &b-1),4,2,1,3,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (p12b - 
     &noab - 1)))))
      END IF
      IF ((p12b .le. p11b) .and. (h13b .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+p11b-1),int_mb(k_range+h13b-1),int_mb(k_range+p12
     &b-1),4,2,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 * (h13b - 1 + noab * (p11b - noab - 1 + nvab * (p12b - 
     &noab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_2',11,MA_E
     &RR)
      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 beta_1_4_3_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h13 )_ytrb + = -1 * Sum ( h5 p3 p4 ) * trb ( p3 p4 h5 h13 )_trb * y ( h5 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 h8b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p4b
      INTEGER h5b
      INTEGER p3b_1
      INTEGER p4b_1
      INTEGER h13b_1
      INTEGER h5b_1
      INTEGER h8b_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 h8b = 1,noab
      DO h13b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+h13b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+h13b-1)) .eq. ieor(irrep
     &_y,irrep_trb)) THEN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_3_1_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
     &13b-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+h13b-1),int_mb(k_sym+h5b-1)))) .eq. irrep_trb) THEN
      CALL TCE_RESTRICTED_4(p3b,p4b,h13b,h5b,p3b_1,p4b_1,h13b_1,h5b_1)
      CALL TCE_RESTRICTED_4(h8b,h5b,p3b,p4b,h8b_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+h13b-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('beta_1_4_3_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_3_1_1',2,MA_ERR)
      IF ((h5b .le. h13b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1
     &),4,3,2,1,1.0d0)
      END IF
      IF ((h13b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h5b_1
     & - 1 + noab * (h13b_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+h13b-1),int_mb(k_range+h5b-1
     &),3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_3_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_3_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_3_1_1',5,MA_ERR)
      IF ((h5b .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 
     &* (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+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. 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 
     &* (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+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('beta_1_4_3_1_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('beta_1_4_3_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_3_1_1',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('
     &beta_1_4_3_1_1',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+h13b-1),1,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h8b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_3_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_3_1_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 beta_1_4_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p12 h13 )_ytrbtrc + = 1 * Sum ( h8 ) * trc ( p12 h8 )_trc * i3 ( h8 h13 )_ytrb
      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 p12b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p12b_1
      INTEGER h8b_1
      INTEGER h8b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO h13b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p12b-1)+int_mb(k_spin+h13b
     &-1).ne.4)) THEN
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h13b-1)) .eq. ieor(irre
     &p_y,ieor(irrep_trb,irrep_trc))) THEN
      dimc = int_mb(k_range+p12b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_3_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h8b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h8b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p12b,h8b,p12b_1,h8b_1)
      CALL TCE_RESTRICTED_2(h8b,h13b,h8b_2,h13b_2)
      dim_common = int_mb(k_range+h8b-1)
      dima_sort = int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h13b-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('beta_1_4_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_3_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h8b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_3_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_3_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_3_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_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('
     &beta_1_4_3_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+p12b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (p12b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_3_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_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 beta_1_4_3_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h5 h6 h13 p3 )_ytrc + = -1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h5 h6 p3 p7 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h5b
      INTEGER h6b
      INTEGER h13b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h13b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO h13b = 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+h13b-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
     &13b-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+h13b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h13b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_3_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+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p7b,h13b,p7b_1,h13b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p3b,p7b,h5b_2,h6b_2,p3b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h13b-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('beta_1_4_3_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_3_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_3_2_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_3_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_3_2_1',5,MA_ERR)
      IF ((p7b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab 
     &* (h5b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p7b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p3b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab 
     &* (h5b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p3b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_3_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('beta_1_4_3_2_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_3_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('
     &beta_1_4_3_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+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+h13b-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 * (h13b - 1 + noab * (h6b - 1 + noab * (h5b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_3_2_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_3_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 beta_1_4_3_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p12 h13 )_ytrctrb + = 1 * Sum ( h5 h6 p3 ) * trb ( p3 p12 h5 h6 )_trb * i3 ( h5 h6 h13 p3 )_ytrc
      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 p12b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER h5b
      INTEGER h6b
      INTEGER p12b_1
      INTEGER p3b_1
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO h13b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p12b-1)+int_mb(k_spin+h13b
     &-1).ne.4)) THEN
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h13b-1)) .eq. ieor(irre
     &p_y,ieor(irrep_trc,irrep_trb))) THEN
      dimc = int_mb(k_range+p12b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_3_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p3b = noab+1,noab+nvab
      DO h5b = 1,noab
      DO h6b = h5b,noab
      IF (int_mb(k_spin+p12b-1)+int_mb(k_spin+p3b-1) .eq. int_mb(k_spin+
     &h5b-1)+int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),ieor(int_mb(k_sym+p3b-1),ieor(int_mb
     &(k_sym+h5b-1),int_mb(k_sym+h6b-1)))) .eq. irrep_trb) THEN
      CALL TCE_RESTRICTED_4(p12b,p3b,h5b,h6b,p12b_1,p3b_1,h5b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,h13b,p3b,h5b_2,h6b_2,h13b_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+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h13b-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('beta_1_4_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_3_2',2,MA_ERR)
      IF ((p3b .le. p12b)) 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 * (p12b_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+p12b-1),int_mb(k_range+h5b-1),int_mb(k_range+h6b-1
     &),2,4,3,1,1.0d0)
      END IF
      IF ((p12b .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 * (p12b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-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('beta_1_4_3_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_3_2',5,MA_ERR)
      IF ((h13b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h13b_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+h13b-1),int_mb(k_range+p3b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_3_2',6,MA_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h5b .eq. h6b) THEN
      nsubh(isubh) = nsubh(isubh) + 1
      ELSE
      isubh = isubh + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsubh(1))/FACTORIAL(nsubh(2)),dbl_mb(k_a_sort),dim_common,dbl_mb(k
     &_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_4_3_2',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_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('
     &beta_1_4_3_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+p12b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (p12b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_3_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_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 beta_1_4_3_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h4 h13 )_ytrc + = -1 * Sum ( h7 p5 p6 ) * trc ( p5 p6 h7 h13 )_trc * 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 h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p6b
      INTEGER h7b
      INTEGER p5b_1
      INTEGER p6b_1
      INTEGER h13b_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 h13b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h13b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h13b-1)) .eq. ieor(irrep
     &_y,irrep_trc)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_3_3_1',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
     &13b-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+h13b-1),int_mb(k_sym+h7b-1)))) .eq. irrep_trc) THEN
      CALL TCE_RESTRICTED_4(p5b,p6b,h13b,h7b,p5b_1,p6b_1,h13b_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+h13b-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('beta_1_4_3_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_3_3_1',2,MA_ERR)
      IF ((h7b .le. h13b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1
     &),4,3,2,1,1.0d0)
      END IF
      IF ((h13b .lt. h7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (h13b_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+h13b-1),int_mb(k_range+h7b-1
     &),3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_3_3_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_3_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_3_3_1',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('beta_1_4_3_3_1',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('beta_1_4_3_3_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_3_3_1',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('
     &beta_1_4_3_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+h13b-1),1,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_3_3_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_3_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 beta_1_4_3_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p12 h13 )_ytrctrb + = -1 * Sum ( h4 ) * trb ( p12 h4 )_trb * i3 ( h4 h13 )_ytrc
      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 p12b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p12b_1
      INTEGER h4b_1
      INTEGER h4b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO h13b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p12b-1)+int_mb(k_spin+h13b
     &-1).ne.4)) THEN
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h13b-1)) .eq. ieor(irre
     &p_y,ieor(irrep_trc,irrep_trb))) THEN
      dimc = int_mb(k_range+p12b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_3_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h4b-1)) .eq. irrep_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p12b,h4b,p12b_1,h4b_1)
      CALL TCE_RESTRICTED_2(h4b,h13b,h4b_2,h13b_2)
      dim_common = int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h13b-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('beta_1_4_3_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_3_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_3_3',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_3_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_3_3',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_3_3',6,MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('beta_1_4_3_3',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_3_3',8,MA_
     &ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_4_3_3',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+p12b-1),2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (p12b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_3_3',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_3_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 beta_1_4_3_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h7 h8 h13 p5 )_ytrb + = -1 * Sum ( p3 ) * trb ( p3 h13 )_trb * y ( h7 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 h7b
      INTEGER h8b
      INTEGER h13b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p3b
      INTEGER p3b_1
      INTEGER h13b_1
      INTEGER h7b_2
      INTEGER h8b_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 h7b = 1,noab
      DO h8b = h7b,noab
      DO h13b = 1,noab
      DO p5b = 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+h13b-1)+int_mb(k_spin+p5b-1).ne.8)) THEN
      IF (int_mb(k_spin+h7b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &13b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h7b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h13b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_trb))
     & THEN
      dimc = int_mb(k_range+h7b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h13b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_3_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+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p3b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p3b,h13b,p3b_1,h13b_1)
      CALL TCE_RESTRICTED_4(h7b,h8b,p5b,p3b,h7b_2,h8b_2,p5b_2,p3b_2)
      dim_common = int_mb(k_range+p3b-1)
      dima_sort = int_mb(k_range+h13b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h7b-1) * int_mb(k_range+h8b-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('beta_1_4_3_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_3_4_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_3_4_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_3_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_3_4_1',5,MA_ERR)
      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 * (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+p5b-1)
     &,4,2,1,3,1.0d0)
      END IF
      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 * (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+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('beta_1_4_3_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('beta_1_4_3_4_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_3_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('
     &beta_1_4_3_4_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+h8b-1),int_mb(k_range+h7b-1),int_mb(k_range+h13b-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 * (h13b - 1 + noab * (h8b - 1 + noab * (h7b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_3_4_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_3_4_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 beta_1_4_3_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p12 h13 )_ytrbtrc + = -1 * Sum ( h7 h8 p5 ) * trc ( p5 p12 h7 h8 )_trc * i3 ( h7 h8 h13 p5 )_ytrb
      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 p12b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER h7b
      INTEGER h8b
      INTEGER p12b_1
      INTEGER p5b_1
      INTEGER h7b_1
      INTEGER h8b_1
      INTEGER h7b_2
      INTEGER h8b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO h13b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p12b-1)+int_mb(k_spin+h13b
     &-1).ne.4)) THEN
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h13b-1)) .eq. ieor(irre
     &p_y,ieor(irrep_trb,irrep_trc))) THEN
      dimc = int_mb(k_range+p12b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_3_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      DO h7b = 1,noab
      DO h8b = h7b,noab
      IF (int_mb(k_spin+p12b-1)+int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+
     &h7b-1)+int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),ieor(int_mb(k_sym+p5b-1),ieor(int_mb
     &(k_sym+h7b-1),int_mb(k_sym+h8b-1)))) .eq. irrep_trc) THEN
      CALL TCE_RESTRICTED_4(p12b,p5b,h7b,h8b,p12b_1,p5b_1,h7b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h7b,h8b,h13b,p5b,h7b_2,h8b_2,h13b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1) * int_mb(k_range+h7b-1) * int_m
     &b(k_range+h8b-1)
      dima_sort = int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h13b-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('beta_1_4_3_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_3_4',2,MA_ERR)
      IF ((p5b .le. p12b)) 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 * (p12b_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+p12b-1),int_mb(k_range+h7b-1),int_mb(k_range+h8b-1
     &),2,4,3,1,1.0d0)
      END IF
      IF ((p12b .lt. p5b)) 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 * (p5b_1 - noab - 1 + nvab * (p12b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+p5b-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('beta_1_4_3_4',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_3_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_3_4',5,MA_ERR)
      IF ((h13b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (h13b_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+h13b-1),int_mb(k_range+p5b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_3_4',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('beta_1_4_3_4',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_3_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('
     &beta_1_4_3_4',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+p12b-1),2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (p12b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_3_4',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_3_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 beta_1_4_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p11 p12 h10 h13 )_ytrbtrctra + = -2 * tra ( p11 h10 )_tra * i2 ( p12 h13 )_ytrbtrc
      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 p11b
      INTEGER p12b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p11b_1
      INTEGER h10b_1
      INTEGER p12b_2
      INTEGER h13b_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 p11b = noab+1,noab+nvab
      DO p12b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h13b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b
     &-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin
     &+h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_m
     &b(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irr
     &ep_trb,ieor(irrep_trc,irrep_tra)))) THEN
      dimc = int_mb(k_range+p11b-1) * int_mb(k_range+p12b-1) * int_mb(k_
     &range+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_3',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_tra
     &) THEN
      CALL TCE_RESTRICTED_2(p11b,h10b,p11b_1,h10b_1)
      CALL TCE_RESTRICTED_2(p12b,h13b,p12b_2,h13b_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+p12b-1) * int_mb(k_range+h13b-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('beta_1_4_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_3',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('beta_1_4_3',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_3',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h13b_
     &2 - 1 + noab * (p12b_2 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_3',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_3',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_4_3',9,MA_ERR)
      IF ((p11b .le. p12b) .and. (h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+p11
     &b-1),4,2,3,1,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (p11b - 
     &noab - 1)))))
      END IF
      IF ((p11b .le. p12b) .and. (h13b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+p11
     &b-1),4,2,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 * (h13b - 1 + noab * (p12b - noab - 1 + nvab * (p11b - 
     &noab - 1)))))
      END IF
      IF ((p12b .le. p11b) .and. (h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+p11
     &b-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),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (p12b - 
     &noab - 1)))))
      END IF
      IF ((p12b .le. p11b) .and. (h13b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+p11
     &b-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 * (h13b - 1 + noab * (p11b - noab - 1 + nvab * (p12b - 
     &noab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_3',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_3',11,MA_E
     &RR)
      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 beta_1_4_4_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h3 h8 h13 p1 )_ytrb + = 1 * Sum ( p5 ) * trb ( p5 h13 )_trb * y ( h3 h8 p1 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 h3b
      INTEGER h8b
      INTEGER h13b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h13b_1
      INTEGER h3b_2
      INTEGER h8b_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 h3b = 1,noab
      DO h8b = h3b,noab
      DO h13b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h3b-1)+int_mb(k_spin+h8b-1
     &)+int_mb(k_spin+h13b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      IF (int_mb(k_spin+h3b-1)+int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+h
     &13b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h3b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(
     &k_sym+h13b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_y,irrep_trb))
     & THEN
      dimc = int_mb(k_range+h3b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h13b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_4_1_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+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h13b,p5b_1,h13b_1)
      CALL TCE_RESTRICTED_4(h3b,h8b,p1b,p5b,h3b_2,h8b_2,p1b_2,p5b_2)
      dim_common = int_mb(k_range+p5b-1)
      dima_sort = int_mb(k_range+h13b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h3b-1) * int_mb(k_range+h8b-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('beta_1_4_4_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_4_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_4_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_4_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_4_1_1',5,MA_ERR)
      IF ((p5b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h8b_2 - 1 + noab 
     &* (h3b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h8b-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
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (h8b_2 - 1 + noab 
     &* (h3b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h8b-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('beta_1_4_4_1_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('beta_1_4_4_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_4_1_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('
     &beta_1_4_4_1_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+h8b-1),int_mb(k_range+h3b-1),int_mb(k_range+h13b-1
     &),3,2,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h13b - 1 + noab * (h8b - 1 + noab * (h3b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_4_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_4_1_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 beta_1_4_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p11 h10 h13 )_ytrbtra + = 1 * Sum ( h3 p1 ) * tra ( p1 p11 h3 h10 )_tra * i3 ( h3 h8 h13 p1 )_ytrb
      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 p11b
      INTEGER h8b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p1b
      INTEGER h3b
      INTEGER p11b_1
      INTEGER p1b_1
      INTEGER h10b_1
      INTEGER h3b_1
      INTEGER h8b_2
      INTEGER h3b_2
      INTEGER h13b_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 p11b = noab+1,noab+nvab
      DO h8b = 1,noab
      DO h10b = 1,noab
      DO h13b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+p11b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h8b-1)+int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),ieor(int_mb(k_sym+p11b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_trb,irrep_tra))) THEN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+p11b-1) * int_mb(k_r
     &ange+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_4_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p1b = noab+1,noab+nvab
      DO h3b = 1,noab
      IF (int_mb(k_spin+p11b-1)+int_mb(k_spin+p1b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h3b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h3b-1)))) .eq. irrep_tra) THEN
      CALL TCE_RESTRICTED_4(p11b,p1b,h10b,h3b,p11b_1,p1b_1,h10b_1,h3b_1)
      CALL TCE_RESTRICTED_4(h8b,h3b,h13b,p1b,h8b_2,h3b_2,h13b_2,p1b_2)
      dim_common = int_mb(k_range+p1b-1) * int_mb(k_range+h3b-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+h8b-1) * int_mb(k_range+h13b-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('beta_1_4_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_4_1',2,MA_ERR)
      IF ((p1b .le. p11b) .and. (h3b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h3b_1 - 1 + noab * (p11b_1 - noab - 1 + nvab * (p1
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p11b-1),int_mb(k_range+h3b-1),int_mb(k_range+h10b-
     &1),4,2,3,1,1.0d0)
      END IF
      IF ((p1b .le. p11b) .and. (h10b .lt. h3b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p11b_1 - noab - 1 + nvab * (p1
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p11b-1),int_mb(k_range+h10b-1),int_mb(k_range+h3b-
     &1),3,2,4,1,-1.0d0)
      END IF
      IF ((p11b .lt. p1b) .and. (h3b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h3b_1 - 1 + noab * (p1b_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+p1b-1),int_mb(k_range+h3b-1),int_mb(k_range+h10b-
     &1),4,1,3,2,-1.0d0)
      END IF
      IF ((p11b .lt. p1b) .and. (h10b .lt. h3b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h3b_1
     & - 1 + noab * (h10b_1 - 1 + noab * (p1b_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+p1b-1),int_mb(k_range+h10b-1),int_mb(k_range+h3b-
     &1),3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_4_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_4_1',5,MA_ERR)
      IF ((h3b .le. h8b) .and. (h13b .le. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (h13b_2 - 1 + noab * (h8b_2 - 1 + noab * (h3b
     &_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+h13b-1),int_mb(k_range+p1b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF ((h8b .lt. h3b) .and. (h13b .le. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (h13b_2 - 1 + noab * (h3b_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+h3b-1),int_mb(k_range+h13b-1),int_mb(k_range+p1b-1
     &),3,1,2,4,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_4_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_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('
     &beta_1_4_4_1',9,MA_ERR)
      IF ((h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h8b-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),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (h8b - 1
     &)))))
      END IF
      IF ((h13b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h8b-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 * (h13b - 1 + noab * (p11b - noab - 1 + nvab * (h8b - 1
     &)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_4_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_4_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 beta_1_4_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p11 p12 h10 h13 )_ytrbtratrc + = 4 * Sum ( h8 ) * trc ( p12 h8 )_trc * i2 ( h8 p11 h10 h13 )_ytrbtra
      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 p12b
      INTEGER p11b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p12b_1
      INTEGER h8b_1
      INTEGER p11b_2
      INTEGER h8b_2
      INTEGER h10b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO p11b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b
     &-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin
     &+h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_m
     &b(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irr
     &ep_trb,ieor(irrep_tra,irrep_trc)))) THEN
      dimc = int_mb(k_range+p11b-1) * int_mb(k_range+p12b-1) * int_mb(k_
     &range+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h8b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h8b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p12b,h8b,p12b_1,h8b_1)
      CALL TCE_RESTRICTED_4(p11b,h8b,h10b,h13b,p11b_2,h8b_2,h10b_2,h13b_
     &2)
      dim_common = int_mb(k_range+h8b-1)
      dima_sort = int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p11b-1) * int_mb(k_range+h10b-1) * int_
     &mb(k_range+h13b-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('beta_1_4_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_4',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h8b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_4',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_4',5,MA_ERR)
      IF ((h8b .le. p11b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h13b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (p11b_2 - noab - 1 + nvab * (h
     &8b_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+p11b-1),int_mb(k_range+h10b-1),int_mb(k_range+h13b
     &-1),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_4',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_4',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_4_4',9,MA_ERR)
      IF ((p11b .le. p12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+p11b-1),int_mb(k_range+p12
     &b-1),3,4,2,1,2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (p11b - 
     &noab - 1)))))
      END IF
      IF ((p12b .le. p11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+p11b-1),int_mb(k_range+p12
     &b-1),4,3,2,1,-2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (p12b - 
     &noab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_4',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_4',11,MA_E
     &RR)
      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 beta_1_4_5_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h3 h4 h13 p5 )_ytrc + = -1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h3 h4 p5 p7 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h3b
      INTEGER h4b
      INTEGER h13b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h13b_1
      INTEGER h3b_2
      INTEGER h4b_2
      INTEGER p5b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h3b = 1,noab
      DO h4b = h3b,noab
      DO h13b = 1,noab
      DO p5b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h3b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h13b-1)+int_mb(k_spin+p5b-1).ne.8)) THEN
      IF (int_mb(k_spin+h3b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &13b-1)+int_mb(k_spin+p5b-1)) THEN
      IF (ieor(int_mb(k_sym+h3b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h13b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h3b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h13b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_5_1_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+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p7b,h13b,p7b_1,h13b_1)
      CALL TCE_RESTRICTED_4(h3b,h4b,p5b,p7b,h3b_2,h4b_2,p5b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h13b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h3b-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('beta_1_4_5_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_5_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_5_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_5_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_5_1_1',5,MA_ERR)
      IF ((p7b .lt. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h4b_2 - 1 + noab 
     &* (h3b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p7b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p5b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h4b_2 - 1 + noab 
     &* (h3b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_5_1_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('beta_1_4_5_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_5_1_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('
     &beta_1_4_5_1_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+h3b-1),int_mb(k_range+h13b-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 * (h13b - 1 + noab * (h4b - 1 + noab * (h3b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_5_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_5_1_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 beta_1_4_5_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( h3 h4 h10 h13 )_ytrctrb + = 1 * Sum ( p5 ) * trb ( p5 h10 )_trb * i3 ( h3 h4 h13 p5 )_ytrc
      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 h3b
      INTEGER h4b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h10b_1
      INTEGER h3b_2
      INTEGER h4b_2
      INTEGER h13b_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 h3b = 1,noab
      DO h4b = h3b,noab
      DO h10b = 1,noab
      DO h13b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h3b-1)+int_mb(k_spin+h4b-1
     &)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h3b-1)+int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h3b-1),ieor(int_mb(k_sym+h4b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trc,irrep_trb))) THEN
      dimc = int_mb(k_range+h3b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_5_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_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h10b,p5b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h3b,h4b,h13b,p5b,h3b_2,h4b_2,h13b_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+h3b-1) * int_mb(k_range+h4b-1) * int_mb
     &(k_range+h13b-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('beta_1_4_5_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_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 * (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('beta_1_4_5_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_5_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_5_1',5,MA_ERR)
      IF ((h13b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (h13b_2 - 1 + noab * (h4b_2 - 1 + noab * (h3b
     &_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h13b-1),int_mb(k_range+p5b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_5_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_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('
     &beta_1_4_5_1',9,MA_ERR)
      IF ((h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+h3b-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),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (h4b - 1 + noab * (h3b - 1)))))
      END IF
      IF ((h13b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+h3b-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 * (h13b - 1 + noab * (h4b - 1 + noab * (h3b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_5_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_5_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 beta_1_4_5(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p11 p12 h10 h13 )_ytrctrbtra + = 1 * Sum ( h3 h4 ) * tra ( p11 p12 h3 h4 )_tra * i2 ( h3 h4 h10 h13 )_ytrctrb
      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 p11b
      INTEGER p12b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h3b
      INTEGER h4b
      INTEGER p11b_1
      INTEGER p12b_1
      INTEGER h3b_1
      INTEGER h4b_1
      INTEGER h3b_2
      INTEGER h4b_2
      INTEGER h10b_2
      INTEGER h13b_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 p11b = noab+1,noab+nvab
      DO p12b = p11b,noab+nvab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b
     &-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin
     &+h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_m
     &b(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irr
     &ep_trc,ieor(irrep_trb,irrep_tra)))) THEN
      dimc = int_mb(k_range+p11b-1) * int_mb(k_range+p12b-1) * int_mb(k_
     &range+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h3b = 1,noab
      DO h4b = h3b,noab
      IF (int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin
     &+h3b-1)+int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_m
     &b(k_sym+h3b-1),int_mb(k_sym+h4b-1)))) .eq. irrep_tra) THEN
      CALL TCE_RESTRICTED_4(p11b,p12b,h3b,h4b,p11b_1,p12b_1,h3b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h3b,h4b,h10b,h13b,h3b_2,h4b_2,h10b_2,h13b_2)
      dim_common = int_mb(k_range+h3b-1) * int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p11b-1) * int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h10b-1) * int_mb(k_range+h13b-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('beta_1_4_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_5',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (h3b_1 - 1 + noab * (p12b_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+p12b-1),int_mb(k_range+h3b-1),int_mb(k_range+h4b-
     &1),2,1,4,3,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_5',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_5',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h13b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (h4b_2 - 1 + noab * (h3b_2 - 1
     &)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h3b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h10b-1),int_mb(k_range+h13b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_5',6,MA_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h3b .eq. h4b) 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('beta_1_4_5',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_5',8,MA_ER
     &R)
      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('
     &beta_1_4_5',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+p12b-1),int_mb(k_range+p11
     &b-1),4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (p11b - 
     &noab - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_5',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_5',11,MA_E
     &RR)
      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 beta_1_4_6_1_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i4 ( h2 h8 h13 p3 )_ytrb + = 1 * Sum ( p5 ) * trb ( p5 h13 )_trb * 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 h13b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h13b_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 = h2b,noab
      DO h13b = 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+h13b-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
     &13b-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+h13b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_trb))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h8b-1) * int_mb(k_ra
     &nge+h13b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_6_1_1_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+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h13b,p5b_1,h13b_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+h13b-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('beta_1_4_6_1_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_6_1_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_6_1_1_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_6_1_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_6_1_1_1',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 * (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 ((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('beta_1_4_6_1_1_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('beta_1_4_6_1_1_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_6_1_1_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('
     &beta_1_4_6_1_1_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+h13b-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 * (h13b - 1 + noab * (h8b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_6_1_1_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_6_1_1_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 beta_1_4_6_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h13 )_ytrbtra + = 1 * Sum ( p3 ) * tra ( p3 h10 )_tra * i4 ( h2 h8 h13 p3 )_ytrb
      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 h13b
      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 h13b_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 = h2b,noab
      DO h10b = 1,noab
      DO h13b = 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+h13b-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+h13b-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+h13b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trb,irrep_tra))) 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+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_6_1_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_tra)
     & THEN
      CALL TCE_RESTRICTED_2(p3b,h10b,p3b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h13b,p3b,h2b_2,h8b_2,h13b_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+h13b-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('beta_1_4_6_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_6_1_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('beta_1_4_6_1_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_6_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_6_1_1',5,MA_ERR)
      IF ((h13b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h13b_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+h13b-1),int_mb(k_range+p3b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_6_1_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('beta_1_4_6_1_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_6_1_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('
     &beta_1_4_6_1_1',9,MA_ERR)
      IF ((h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-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),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h13b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-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 * (h13b - 1 + noab * (h8b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_6_1_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_6_1_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 beta_1_4_6_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h13 )_ytrbtratrc + = 1 * Sum ( h8 ) * trc ( p12 h8 )_trc * i3 ( h2 h8 h10 h13 )_ytrbtra
      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 p12b
      INTEGER h2b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p12b_1
      INTEGER h8b_1
      INTEGER h2b_2
      INTEGER h8b_2
      INTEGER h10b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_trb,ieor(irrep_tra,irrep_trc)))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_6_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h8b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h8b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p12b,h8b,p12b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h2b,h8b,h10b,h13b,h2b_2,h8b_2,h10b_2,h13b_2)
      dim_common = int_mb(k_range+h8b-1)
      dima_sort = int_mb(k_range+p12b-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+h13b-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('beta_1_4_6_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_6_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h8b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_6_1',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_6_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_6_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),(h13b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h13b-
     &1),4,3,2,1,-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),(h13b_
     &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+h13b-
     &1),4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_6_1',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_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('
     &beta_1_4_6_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+h2b-1),int_mb(k_range+p12b
     &-1),3,4,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (h2b - 1
     &)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_6_1',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_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 beta_1_4_6_2_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i4 ( h2 h6 h13 p3 )_ytrc + = 1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h2 h6 p3 p7 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h6b
      INTEGER h13b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h13b_1
      INTEGER h2b_2
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h6b = h2b,noab
      DO h13b = 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+h6b-1
     &)+int_mb(k_spin+h13b-1)+int_mb(k_spin+p3b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+h6b-1) .eq. int_mb(k_spin+h
     &13b-1)+int_mb(k_spin+p3b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+h6b-1),ieor(int_mb(
     &k_sym+h13b-1),int_mb(k_sym+p3b-1)))) .eq. ieor(irrep_y,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h6b-1) * int_mb(k_ra
     &nge+h13b-1) * int_mb(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_6_2_1_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+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p7b,h13b,p7b_1,h13b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,p3b,p7b,h2b_2,h6b_2,p3b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h13b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h2b-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('beta_1_4_6_2_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_6_2_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_6_2_1_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_6_2_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_6_2_1_1',5,MA_ERR)
      IF ((p7b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab 
     &* (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+p7b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p3b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p3b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab 
     &* (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+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_6_2_1_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('beta_1_4_6_2_1_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_6_2_1_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('
     &beta_1_4_6_2_1_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+h2b-1),int_mb(k_range+h13b-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 * (h13b - 1 + noab * (h6b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_6_2_1_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_6_2_1_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 beta_1_4_6_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h6 h10 h13 )_ytrctra + = 1 * Sum ( p3 ) * tra ( p3 h10 )_tra * i4 ( h2 h6 h13 p3 )_ytrc
      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 h13b
      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 h13b_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 = h2b,noab
      DO h10b = 1,noab
      DO h13b = 1,noab
      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+h13b-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+h13b-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+h13b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trc,irrep_tra))) 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+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_6_2_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_tra)
     & THEN
      CALL TCE_RESTRICTED_2(p3b,h10b,p3b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,h13b,p3b,h2b_2,h6b_2,h13b_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+h13b-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('beta_1_4_6_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_6_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 * (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('beta_1_4_6_2_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_6_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_6_2_1',5,MA_ERR)
      IF ((h13b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h13b_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+h13b-1),int_mb(k_range+p3b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_6_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('beta_1_4_6_2_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_6_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('
     &beta_1_4_6_2_1',9,MA_ERR)
      IF ((h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-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/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (h6b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h13b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h6b-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 * (h13b - 1 + noab * (h6b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_6_2_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_6_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 beta_1_4_6_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h13 )_ytrctratrb + = 1 * Sum ( h6 ) * trb ( p12 h6 )_trb * i3 ( h2 h6 h10 h13 )_ytrctra
      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 p12b
      INTEGER h2b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h6b
      INTEGER p12b_1
      INTEGER h6b_1
      INTEGER h2b_2
      INTEGER h6b_2
      INTEGER h10b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_trc,ieor(irrep_tra,irrep_trb)))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_6_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h6b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h6b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h6b-1)) .eq. irrep_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p12b,h6b,p12b_1,h6b_1)
      CALL TCE_RESTRICTED_4(h2b,h6b,h10b,h13b,h2b_2,h6b_2,h10b_2,h13b_2)
      dim_common = int_mb(k_range+h6b-1)
      dima_sort = int_mb(k_range+p12b-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+h13b-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('beta_1_4_6_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_6_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h6b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h6b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_6_2',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_6_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_6_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),(h13b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h13b-
     &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),(h13b_
     &2 - 1 + noab * (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+h13b-
     &1),4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_6_2',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_6_2',8,MA_
     &ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_4_6_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+h2b-1),int_mb(k_range+p12b
     &-1),3,4,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (h2b - 1
     &)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_6_2',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_6_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 beta_1_4_6_3_1_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i4 ( h2 h4 h13 p5 )_ytrc + = 1 * Sum ( p7 ) * trc ( p7 h13 )_trc * y ( h2 h4 p5 p7 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTVAL
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h2b
      INTEGER h4b
      INTEGER h13b
      INTEGER p5b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h13b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER p5b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTVAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTVAL(nprocs)
      DO h2b = 1,noab
      DO h4b = h2b,noab
      DO h13b = 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+h13b-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
     &13b-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+h13b-1),int_mb(k_sym+p5b-1)))) .eq. ieor(irrep_y,irrep_trc))
     & THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+h4b-1) * int_mb(k_ra
     &nge+h13b-1) * int_mb(k_range+p5b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_6_3_1_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+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h13b-1)) .eq. irrep_trc)
     & THEN
      CALL TCE_RESTRICTED_2(p7b,h13b,p7b_1,h13b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,p5b,p7b,h2b_2,h4b_2,p5b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h13b-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('beta_1_4_6_3_1_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_6_3_1_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &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+h13b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_6_3_1_1',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_6_3_1_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_6_3_1_1',5,MA_ERR)
      IF ((p7b .lt. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h4b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p7b-1),int_mb(k_range+p5b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p5b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p5b_2 - noab - 1 + nvab * (h4b_2 - 1 + noab 
     &* (h2b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h2b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p5b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_6_3_1_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('beta_1_4_6_3_1_1',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_6_3_1_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('
     &beta_1_4_6_3_1_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+h13b-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 * (h13b - 1 + noab * (h4b - 1 + noab * (h2b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_6_3_1_1',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_6_3_1_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 beta_1_4_6_3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_of
     &fset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 h13 )_ytrctrb + = 1 * Sum ( p5 ) * trb ( p5 h10 )_trb * i4 ( h2 h4 h13 p5 )_ytrc
      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 h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p5b
      INTEGER p5b_1
      INTEGER h10b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h13b_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 = h2b,noab
      DO h10b = 1,noab
      DO h13b = 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+h13b-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+h13b-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+h13b-1)))) .eq. ieor(irrep_y,ieor(irrep
     &_trc,irrep_trb))) 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+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_6_3_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p5b = noab+1,noab+nvab
      IF (int_mb(k_spin+p5b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p5b-1),int_mb(k_sym+h10b-1)) .eq. irrep_trb)
     & THEN
      CALL TCE_RESTRICTED_2(p5b,h10b,p5b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h13b,p5b,h2b_2,h4b_2,h13b_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+h4b-1) * int_mb
     &(k_range+h13b-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('beta_1_4_6_3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_6_3_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (p5b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p5b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_6_3_1',3,MA_ERR
     &)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_6_3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_6_3_1',5,MA_ERR)
      IF ((h13b .le. p5b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p5b_2
     & - noab - 1 + nvab * (h13b_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+h13b-1),int_mb(k_range+p5b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_6_3_1',7,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_6_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('
     &beta_1_4_6_3_1',9,MA_ERR)
      IF ((h10b .le. h13b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-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/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))))
      END IF
      IF ((h13b .le. h10b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h4b-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 * (h13b - 1 + noab * (h4b - 1 + noab * (h2b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_6_3_1',10,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_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 beta_1_4_6_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offs
     &et)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 p12 h10 h13 )_ytrctrbtra + = 1/2 * Sum ( h4 ) * tra ( p12 h4 )_tra * i3 ( h2 h4 h10 h13 )_ytrctrb
      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 p12b
      INTEGER h2b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b
      INTEGER p12b_1
      INTEGER h4b_1
      INTEGER h2b_2
      INTEGER h4b_2
      INTEGER h10b_2
      INTEGER h13b_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 p12b = noab+1,noab+nvab
      DO h2b = 1,noab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-
     &1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+h2b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+
     &h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+h2b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_mb
     &(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irre
     &p_trc,ieor(irrep_trb,irrep_tra)))) THEN
      dimc = int_mb(k_range+h2b-1) * int_mb(k_range+p12b-1) * int_mb(k_r
     &ange+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_6_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h4b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h4b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h4b-1)) .eq. irrep_tra)
     & THEN
      CALL TCE_RESTRICTED_2(p12b,h4b,p12b_1,h4b_1)
      CALL TCE_RESTRICTED_4(h2b,h4b,h10b,h13b,h2b_2,h4b_2,h10b_2,h13b_2)
      dim_common = int_mb(k_range+h4b-1)
      dima_sort = int_mb(k_range+p12b-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+h13b-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('beta_1_4_6_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_6_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h4b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h4b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_6_3',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_6_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_6_3',5,MA_ERR)
      IF ((h4b .lt. h2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h13b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (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+h10b-1),int_mb(k_range+h13b-
     &1),4,3,2,1,-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),(h13b_
     &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+h13b-
     &1),4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_6_3',7,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_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('
     &beta_1_4_6_3',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+h2b-1),int_mb(k_range+p12b
     &-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),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (h2b - 1
     &)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_6_3',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_6_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 beta_1_4_6(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset
     &)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( p11 p12 h10 h13 )_ytrbtratrct + = -4 * Sum ( h2 ) * t ( p11 h2 )_t * i2 ( h2 p12 h10 h13 )_ytrbtratrc
      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 p11b
      INTEGER p12b
      INTEGER h10b
      INTEGER h13b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h2b
      INTEGER p11b_1
      INTEGER h2b_1
      INTEGER p12b_2
      INTEGER h2b_2
      INTEGER h10b_2
      INTEGER h13b_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 p11b = noab+1,noab+nvab
      DO p12b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b
     &-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h13b-1).ne.8)) THEN
      IF (int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin
     &+h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_m
     &b(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irr
     &ep_trb,ieor(irrep_tra,ieor(irrep_trc,irrep_t))))) THEN
      dimc = int_mb(k_range+p11b-1) * int_mb(k_range+p12b-1) * int_mb(k_
     &range+h10b-1) * int_mb(k_range+h13b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4_6',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h2b = 1,noab
      IF (int_mb(k_spin+p11b-1) .eq. int_mb(k_spin+h2b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),int_mb(k_sym+h2b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p11b,h2b,p11b_1,h2b_1)
      CALL TCE_RESTRICTED_4(p12b,h2b,h10b,h13b,p12b_2,h2b_2,h10b_2,h13b_
     &2)
      dim_common = int_mb(k_range+h2b-1)
      dima_sort = int_mb(k_range+p11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p12b-1) * int_mb(k_range+h10b-1) * int_
     &mb(k_range+h13b-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('beta_1_4_6',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4_6',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h2b_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+h2b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4_6',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4_6',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4_6',5,MA_ERR)
      IF ((h2b .le. p12b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h13b_
     &2 - 1 + noab * (h10b_2 - 1 + noab * (p12b_2 - noab - 1 + nvab * (h
     &2b_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+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+h13b
     &-1),4,3,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4_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('beta_1_4_6',7,MA_ER
     &R)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4_6',8,MA_ER
     &R)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_4_6',9,MA_ERR)
      IF ((p11b .le. p12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+p12b-1),int_mb(k_range+p11
     &b-1),4,3,2,1,-2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p12b - noab - 1 + nvab * (p11b - 
     &noab - 1)))))
      END IF
      IF ((p12b .le. p11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h13b-1
     &),int_mb(k_range+h10b-1),int_mb(k_range+p12b-1),int_mb(k_range+p11
     &b-1),3,4,2,1,2.0d0/1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h13b 
     &- 1 + noab * (h10b - 1 + noab * (p11b - noab - 1 + nvab * (p12b - 
     &noab - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4_6',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4_6',11,MA_E
     &RR)
      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 beta_1_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_offset)
C     $Id: beta_1_all.F 25265 2014-02-14 23:57:19Z kowalski $
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 ( )_ytrbtrctrav + = -1/4 * Sum ( p11 p12 h10 h13 ) * i1 ( p11 p12 h10 h13 )_ytrbtrctra * v ( h10 h13 p11 p12 )_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 dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p11b
      INTEGER p12b
      INTEGER h10b
      INTEGER h13b
      INTEGER p11b_1
      INTEGER p12b_1
      INTEGER h10b_1
      INTEGER h13b_1
      INTEGER h10b_2
      INTEGER h13b_2
      INTEGER p11b_2
      INTEGER p12b_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 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)
      IF (next.eq.count) THEN
      IF (0 .eq. ieor(irrep_y,ieor(irrep_trb,ieor(irrep_trc,ieor(irrep_t
     &ra,irrep_v))))) THEN
      dimc = 1
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('beta_1_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p11b = noab+1,noab+nvab
      DO p12b = p11b,noab+nvab
      DO h10b = 1,noab
      DO h13b = h10b,noab
      IF (int_mb(k_spin+p11b-1)+int_mb(k_spin+p12b-1) .eq. int_mb(k_spin
     &+h10b-1)+int_mb(k_spin+h13b-1)) THEN
      IF (ieor(int_mb(k_sym+p11b-1),ieor(int_mb(k_sym+p12b-1),ieor(int_m
     &b(k_sym+h10b-1),int_mb(k_sym+h13b-1)))) .eq. ieor(irrep_y,ieor(irr
     &ep_trb,ieor(irrep_trc,irrep_tra)))) THEN
      CALL TCE_RESTRICTED_4(p11b,p12b,h10b,h13b,p11b_1,p12b_1,h10b_1,h13
     &b_1)
      CALL TCE_RESTRICTED_4(h10b,h13b,p11b,p12b,h10b_2,h13b_2,p11b_2,p12
     &b_2)
      dim_common = int_mb(k_range+p11b-1) * int_mb(k_range+p12b-1) * int
     &_mb(k_range+h10b-1) * int_mb(k_range+h13b-1)
      dima_sort = 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('beta_1_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &beta_1_4',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h13b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p12b_1 - noab - 1 + nvab * (p
     &11b_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+p12b-1),int_mb(k_range+h10b-1),int_mb(k_range+h13
     &b-1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('beta_1_4',3,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('beta_1_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &beta_1_4',5,MA_ERR)
      if(.not.intorb) then
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p12b_
     &2 - 1 + (noab+nvab) * (p11b_2 - 1 + (noab+nvab) * (h13b_2 - 1 + (n
     &oab+nvab) * (h10b_2 - 1)))))
      else
      CALL GET_HASH_BLOCK_I(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),
     &(p12b_
     &2 - 1 + (noab+nvab) * (p11b_2 - 1 + (noab+nvab) * (h13b_2 - 1 + (n
     &oab+nvab) * (h10b_2 - 1)))),p12b_2,p11b_2,h13b_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+h13b-1),int_mb(k_range+p11b-1),int_mb(k_range+p12
     &b-1),2,1,4,3,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('beta_1_4',6,MA_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p11b .eq. p12b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h10b .eq. h13b) THEN
      nsubh(isubh) = nsubh(isubh) + 1
      ELSE
      isubh = isubh + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,4.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2))/FACTORIAL(nsubh(1))/FACTORIAL(ns
     &ubh(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('beta_1_4',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('beta_1_4',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &beta_1_4',9,MA_ERR)
      CALL TCE_SORT_0(dbl_mb(k_c_sort),dbl_mb(k_c),-1.0d0/4.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),0)
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('beta_1_4',10,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('beta_1_4',11,MA_ERR
     &)
      END IF
      next = NXTVAL(nprocs)
      END IF
      count = count + 1
      next = NXTVAL(-nprocs)
      call GA_SYNC()
      RETURN
      END
