      CHARACTER KFILE*32
      DIMENSION N(100),M(100)
      DATA IH1,IH2,K1,K2,L1,L2/0,10,0,10,0,10/
      DATA M/100*0/
      DATA ATEST/'Y'/
	DATA IO5,IO6/5,6/
      WRITE(IO6,22)
   22 FORMAT(///' Program to calculate hkl''s from n**2 values'/
     1 ' for Cubic, Tetragonal or Hexagonal cells')
    6 WRITE(IO6,23)
   23 FORMAT(///' ENTER crystal system: '/' 1 for Cubic'/
     1' 2 for Hexagonal'/
     X' 3 for Tetragonal')
      READ(IO5,24)IGO
      IGO = IGO - 2.
   24 FORMAT(I1)
C      WRITE(IO6,25)IH1,IH2
C   25 FORMAT(///' Do you wish to input max and min for',/,
C     X' h,k,l?  (if NO,' ,I3,' and ',I3, ' will be used)')
C      READ(IO5,26)A
   26 FORMAT(A1)
C      IF(A.NE.ATEST) GO TO 11
C      WRITE(IO6,28)
C   28 FORMAT(///' ENTER hmin,hmax,kmin,kmax,lmin,lmax SEPERATED',
C     1' BY COMMAS')
C      READ(IO5,29)(IH1,IH2,K1,K2,L1,L2)
C   29 FORMAT(6I)
   11 IF(IGO)12,13,14
   13 WRITE(IO6,42)
   42 FORMAT(///' INPUT hh+hk+kk and ll seperated by a ',
     1'comma in I format.'/' After last value enter a 0')
      GO TO 15
   14 WRITE(IO6,41)
   41 FORMAT(///' INPUT hh+kk and ll seperated by a ',
     1'comma in I format.'/' After last value enter a 0')
      GO TO 15
   12 WRITE(IO6,40)
   40 FORMAT(///' INPUT n (i.e. hh+kk+ll) in I format ',
     1 ' After last value enter 0')
   15 DO 31 I=1,100
      READ(IO5,44)(N(I),M(I))
      IF(N(I).EQ.0)GO TO 32
   31 CONTINUE
   32 WRITE(IO6,33)
   33 FORMAT(//,5X,'n',3X,'h',3X'k',3X'l')
   44 FORMAT(2I)
      I=I-1
      DO 20 J=1,I
      C=M(J)
      L4=SQRT(C)
      DO 20 IH=IH1,IH2
      DO 20 K=K1,K2
      IF(IGO)1,2,3
    1 DO 10 L=L1,L2
      TEST1=IH**2+K**2+L**2
      IF(TEST1.EQ.N(J))WRITE(IO6,21)(N(J),IH,K,L)
   10 CONTINUE
      GO TO 20
    2 TEST1=IH**2+IH*K+K**2
      IF(TEST1.EQ.N(J))WRITE(IO6,21)(N(J),IH,K,L4)
      GO TO 20
    3 TEST1=IH**2+K**2
      IF(TEST1.EQ.N(J))WRITE(IO6,21)(N(J),IH,K,L4)
   20 CONTINUE
   21 FORMAT(2X,4I4)
      WRITE(IO6,5)
    5 FORMAT(///' Do you wish another run? (Y or N)')
      READ(IO5,26)B
      IF(B.EQ.ATEST)GO TO 6
      STOP
      END
