      subroutine alewald()

      implicit none
      include 'arraysize.inc'
      include 'spur_scan.inc'
      
c...	constants

c...	passed variables

c...	local variables
c0111Unused      real magq,dum,qdiff(n)
      real a,pi
      integer i, j, h(3,nal)

C  Read in the aluminum peaks to be considered.
C

      data (h(i,1),i=1,3) / 1,1,1 /
      data (h(i,2),i=1,3) / 2,0,0 /
      data (h(i,3),i=1,3) / 2,2,0 /
      data (h(i,4),i=1,3) / 3,1,1 /
      data (h(i,5),i=1,3) / 2,2,2 /
      data (h(i,6),i=1,3) / 4,0,0 /
      data (h(i,7),i=1,3) / 3,3,1 /
      data (h(i,8),i=1,3) / 4,2,0 /
      data (h(i,9),i=1,3) / 4,2,2 /
      data (h(i,10),i=1,3) / 3,3,3 /
      data (h(i,11),i=1,3) / 4,4,0 /
      data (h(i,12),i=1,3) / 5,3,1 /
      data (h(i,13),i=1,3) / 6,0,0 /
      
C     Read in the aluminum lattice constant.

      data a / 4.04096 /

      pi=4.0*atan(1.0)

C  Calculate the aluminum G's.

c01Dec      do i=1,n
      do i=1,nal
         Gal(i)=2*pi/a*sqrt(float(h(1,i)**2+h(2,i)**2+h(3,i)**2))
C         write(*,*) g(i)
         do j=1,3
            hklal(j,i)=h(j,i)
         enddo
      enddo

C      magq=sqrt(q(1)**2.0+q(2)**2.0)

C  Calculate the differences

C      do i=1,n
C          qdiff(i)=abs(magq-g(i))
C      enddo

C  sort in ascending order up to the first 3

C      do k=1,3
C        do i=1+k,n
C           if (qdiff(i).lt.qdiff(k)) then
C  swap 'em and the g values
C             dum=qdiff(i)
C             qdiff(i)=qdiff(k)
C             qdiff(k)=dum
C             dum=g(i)
C             g(i)=g(k)
C             g(k)=dum
C           endif
C        enddo
C      enddo
      
C      do k=1,n
C        write(*,'(1x,f5.2,1x,f5.2)') g(k),qdiff(k)
C      enddo
      
C Right now it just outputs the closest one.

C      write(*,77) 'Closest aluminum Q is ',g(1)
C 77   format(a,f5.2)

      return
      end








