ckbn  Kiran Bhaskaran-Nair modified from tce_x2_offset.F
      SUBROUTINE tce_eax2_offset(l_a_offset,k_a_offset,size)
C     $Id: tce_eax2_offset.F 25748 2014-06-08 07:53:05Z d3y133 $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     x ( p2 p4 h1 h3 )_x
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
#include "stdio.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER p2b
      INTEGER p4b
      INTEGER h1b
      INTEGER h3b
      length = 0
      DO p2b = noab+1,noab+nvab
      DO p4b = p2b,noab+nvab
      DO h1b = 1,noab
c#ifndef EACCSD
c      DO h3b = h1b,noab
c      IF (int_mb(k_spin+p2b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
c     &1b-1)+int_mb(k_spin+h3b-1)) THEN
c      IF (ieor(int_mb(k_sym+p2b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
c     &k_sym+h1b-1),int_mb(k_sym+h3b-1)))) .eq. irrep_x) THEN
c      IF ((.not.restricted).or.(int_mb(k_spin+p2b-1)+int_mb(k_spin+p4b-1
c     &)+int_mb(k_spin+h1b-1)+int_mb(k_spin+h3b-1).ne.8)) THEN
c#else
      DO h3b = 1,1
      IF (int_mb(k_spin+p2b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &1b-1)+ ea_unused_spin) THEN
      IF (ieor(int_mb(k_sym+p2b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h1b-1),ea_unused_sym))) .eq. irrep_x) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p2b-1)+int_mb(k_spin+p4b-1
     &)+int_mb(k_spin+h1b-1)+ ea_unused_spin .ne.8)) THEN
c#endif
      length = length + 1
      END IF
      END IF
      END IF
c#ifndef EACCSD
      END DO
c#endif
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'tce_x2_offset',l_a_offset,
     1k_a_offset)) CALL ERRQUIT('tce_x2_offset',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO p2b = noab+1,noab+nvab
      DO p4b = p2b,noab+nvab
      DO h1b = 1,noab
c#ifndef EACCSD
c      DO h3b = h1b,noab
c      IF (int_mb(k_spin+p2b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
c     &1b-1)+int_mb(k_spin+h3b-1)) THEN
c      IF (ieor(int_mb(k_sym+p2b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
c     &k_sym+h1b-1),int_mb(k_sym+h3b-1)))) .eq. irrep_x) THEN
c      IF ((.not.restricted).or.(int_mb(k_spin+p2b-1)+int_mb(k_spin+p4b-1
c     &)+int_mb(k_spin+h1b-1)+int_mb(k_spin+h3b-1).ne.8)) THEN
c#else
      DO h3b = 1,1
      IF (int_mb(k_spin+p2b-1)+int_mb(k_spin+p4b-1) .eq. int_mb(k_spin+h
     &1b-1)+ ea_unused_spin ) THEN
      IF (ieor(int_mb(k_sym+p2b-1),ieor(int_mb(k_sym+p4b-1),ieor(int_mb(
     &k_sym+h1b-1), ea_unused_sym))) .eq. irrep_x) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p2b-1)+int_mb(k_spin+p4b-1
     &)+int_mb(k_spin+h1b-1)+ ea_unused_spin .ne.8)) THEN
c#endif
      addr = addr + 1
      int_mb(k_a_offset+addr) = h3b - 1 + noab * (h1b - 1 + noab * (p4b 
     &- noab - 1 + nvab * (p2b - noab - 1)))
      int_mb(k_a_offset+length+addr) = size
ckbn      write(LuOut,*) "Leng addr key size ",length,addr,
ckbn     + h3b - 1 + noab * (h1b - 1 + noab * (p4b- noab - 1 + nvab * 
ckbn     + (p2b - noab - 1))), size
ckbn       call util_flush(LuOut)
ckbn      size = size + int_mb(k_range+p2b-1) * int_mb(k_range+p4b-1) * int_
ckbn     &mb(k_range+h1b-1) * int_mb(k_range+h3b-1)
      size = size + int_mb(k_range+p2b-1) * int_mb(k_range+p4b-1) * int_
     &mb(k_range+h1b-1) * 1
      END IF
      END IF
      END IF
c#ifndef EACCSD
      END DO
c#endif
      END DO
      END DO
      END DO
      RETURN
      END
