      SUBROUTINE wheneq(n,x,incx,target,index,nn)
      include 'processors.h'
      INTEGER n
      REAL, dimension(n):: x
      INTEGER, dimension(n):: indx,gcf_flag
      INTEGER, dimension(30000):: index
      INTEGER incx
      REAL target
      INTEGER nn
      INTEGER pos, i
!hpf$ distribute index(block) onto PROC_ARRAY_1D
!hpf$ distribute x(block) onto PROC_ARRAY_1D
!hpf$ align with x:: gcf_flag,indx

C****************************************************************
      where(x.eq.target)
        gcf_flag=1
      elsewhere
        gcf_flag=0
      endwhere
      indx=0
c      forall(i=1:n,gcf_flag(i).ne.0) 
c     &       indx(i)=sum(gcf_flag(1:i),DIM=1)
      do i=1,n
        if(gcf_flag(i).ne.0) then 
            indx(i)=sum(gcf_flag(1:i),DIM=1)
        end if
      end do
      nn=maxval(indx)
      if(nn.gt.30000) then
       index=0
       return
      else
       index=0
c       forall(i=1:n,indx(i).ne.0) index(indx(i))=i
       do i=1,n
         if(indx(i).ne.0) index(indx(i))=i
       end do

c      do i=1,n
c       if(indx(i).ne.0) then
c         index(indx(i))=i
c         write(6,*) i,indx(i),index(indx(i))
c       endif
c      enddo

      endif

      return
      END

      SUBROUTINE whenigt(n,x,incx,target,index,nn)
      include 'processors.h'
      INTEGER n
      REAL, dimension(n):: x
      INTEGER, dimension(n):: indx,index,gcf_flag
      INTEGER incx
      REAL target
      INTEGER nn
      INTEGER pos, i
!hpf$ distribute index(block) onto PROC_ARRAY_1D
!hpf$ distribute x(block) onto PROC_ARRAY_1D
!hpf$ align with x:: gcf_flag,indx

      where(x.gt.target)
        gcf_flag=1
      elsewhere
        gcf_flag=0
      endwhere
c      forall(i=1:n,gcf_flag(i).ne.0) 
c     &       indx(i)=sum(gcf_flag(1:i),DIM=1)
      do i=1,n
        if(gcf_flag(i).ne.0) then 
            indx(i)=sum(gcf_flag(1:i),DIM=1)
        end if
      end do
      nn=maxval(indx)
      index=0
c      forall(i=1:n,gcf_flag(i).ne.0) index(indx(i))=i
      do i=1,n
        if(gcf_flag(i).ne.0) index(indx(i))=i
      end do
      return
      END

