      SUBROUTINE kloc3(kx,ky,kz,n,loc)

c   kx, ky, kz are integer values of wavevector
c   N(3):     N(1) = num grid points in x direction, etc.
c   loc is position of imaginary part
c
c   to get Kx,ky,kz given loc:
c  specify N(3), and loc then
c      call kloc3(kx,ky,kz,n,loc)
c    returns the needed values of kx, ky, kz
c
c  to get loc, given kx, ky, kz:
c  use entry lloc3
c       cal lloc3(kx,ky,kz,n,loc)
c
      dimension n(10)
      n2d=n(2)*(n(1)+2)
      ntstk=n2d*(n(3)/2+1)
      kz=(loc-1)/n2d
      nrem=loc-kz*n2d
      IF (loc .GT. ntstk)go to 1
      go to 2
 1      CONTINUE
      kz=kz-n(3)
 2      CONTINUE
      CALL kloc(kxx,kyy,n,nrem)
      kx=kxx
      ky=kyy
      return
C  -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

      ENTRY lloc3(kx,ky,kz,n,loc)
      nadd=0
      n2d=n(2)*(n(1)+2)
      IF (kz .LT. 0)nadd=n(3)
      loc=n2d*(nadd+kz)
      CALL lloc(kx,ky,n,loc2)
      loc=loc+loc2
c        loc is the position of the imag. part
      return
      end

        SUBROUTINE KLOC(KX,KY,N,LOC)

        DIMENSION N(10)
        NINROW=N(1)+2
        NTOP=NINROW*(N(2)/2+1)
        IF (LOC .GT. (NINROW*N(2)))GO TO 2
        IF (LOC .GT. NTOP) GO TO 1
        KY=(LOC-1)/NINROW
        KX=(LOC-KY*NINROW-1)/2
        RETURN
 1      KY=1-N(2)/2+(LOC-NTOP-1)/NINROW
        KX=(LOC-NTOP-(KY+N(2)/2-1)*NINROW-1)/2
        RETURN
 2      WRITE (6,10)LOC
 10     FORMAT('0','ERROR IN KLOC,LOC TOO LARGE',2X,I10)
        RETURN
C  -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

        ENTRY LLOC(KX,KY,N,LOC)
        NADD=0
        NINROW=N(1)+2
        IF (KY .LT. 0)NADD=N(2)
        LOC=NINROW*(NADD+KY)+2*(KX+1)
C                     LOC IS THE IMAG. POSITION
C
        RETURN
        END


