      CHARACTER*5 SCHNAM
      CHARACTER*10 HMNAME
      REAL*8 XX(3),AXX(3),AM,AXXM(3,50)
      INTEGER IKA(2,10)
      INTEGER JB(2,3,30),XYZ(3,30),NPOS(30)
      INTEGER XYZWM(3,48),JAM(2,3,48)
      CHARACTER*1 MPOS(30),A

      OPEN(3,FILE='generator',IOSTAT=ISO,STATUS='OLD')
      WRITE(6,*) ISO
      IF(ISO.NE.0) STOP
      OPEN(4,FILE='wycoff',IOSTAT=ISO,STATUS='OLD')
      WRITE(6,*) ISO
      IF(ISO.NE.0) STOP

   12 WRITE(6,*) ' SELECT SCHNAM(1),HMNAME(2),SPACE GR. NO(3)'
      READ(5,*) NSE 
      IF(NSE.EQ.3) THEN 
         WRITE(6,*) ' SPACE GROUP NUMBER?'
         READ(5,*) NN
         CALL TSNTNM(NN,3,NC,SCHNAM,HMNAME)
      ELSE IF(NSE.EQ.1) THEN
         WRITE(6,*) ' SCHNAM?'
         READ(5,*) SCHNAM
         CALL TSCHTN(SCHNAM,3,NC,NN,HMNAME)
      ELSE IF(NSE.EQ.2) THEN
         WRITE(6,*) ' HMNAME?'
         READ(5,500) HMNAME
  500    FORMAT(A10)
         CALL TSHMTN(HMNAME,3,NC,NN,SCHNAM)
      ELSE
         GO TO 12
      END IF
      WRITE(6,*) NN,' ',SCHNAM,' ',HMNAME,' NUMBER OF CHOICES= ',NC
      WRITE(6,*) ' CHOICE NO?'
      READ(5,*) NNC
      IF(NNC.GT.NC) GO TO 12
      CALL TSPNGE(NN,NNC,3)
      CALL TSWYRD(NN,NNC,4,NUC,NPOS,MPOS,XYZ,JB)
      WRITE(6,*) ' THIS SPACE GROUP HAS THE FOLLOWING WYCOFF POSITION' 
      DO 1 IWP=1,NUC
      WRITE(6,600)  NPOS(IWP),MPOS(IWP)
     &           ,(XYZ(K,IWP),(JB(J,K,IWP),J=1,2),K=1,3)
  600 FORMAT(I5,A1,3(I4,I2,'/',I1))
    1 CONTINUE
      NKA=0
      NATM=0
    7 WRITE(6,*) ' POSITION NAME AND PARAMETERS?'
      READ(5,*) A,XX
      IF(A.EQ.'0') GO TO 6
      NKA=NKA+1
       CALL TSWYCF(A,NUC,NPOS,MPOS,XYZ,JB
     &  ,NSITE,XYZWM,JAM)
      IKA(1,NKA)=NATM+1
       DO 4 ISIT=1,NSITE
           DO 5 I=1,3
               AM=JAM(2,I,ISIT)
               AXX(I)=JAM(1,I,ISIT)/AM
               IXYZ=IABS(XYZWM(I,ISIT))
               IF(IXYZ.EQ.4) AM=XX(1)-XX(2)
               IF(IXYZ.EQ.5) AM=2.0D0*XX(1)
               IF(IXYZ.GE.1.AND.IXYZ.LE.3) AM=XX(IXYZ)
               IF(XYZWM(I,ISIT).GT.0) AXX(I)=AXX(I)+AM  
               IF(XYZWM(I,ISIT).LT.0) AXX(I)=AXX(I)-AM  
               IF(AXX(I).LT.0.0) AXX(I)=AXX(I)+1.0D0
               IF(AXX(I).GT.1.0) AXX(I)=AXX(I)-1.0D0
    5      CONTINUE
           WRITE(6,602) ISIT,AXX
           NATM=NATM+1
           DO 8 K=1,3
             AXXM(K,NATM)=AXX(K)
    8      CONTINUE  
  602      FORMAT(I3,3F18.14)
    4 CONTINUE
      IKA(2,NKA)=NATM
      GO TO 7
    6 CONTINUE
      WRITE(21,*) NATM,NKA
      WRITE(21,*) ((IKA(I,J),I=1,2),J=1,NKA)
      DO 9 I=1,NATM
      WRITE(21,601) (AXXM(K,I),K=1,3)
  601 FORMAT(3F18.14)
    9 CONTINUE
C      CLOSE(3)
C      CLOSE(4)
      CLOSE(21)
      STOP
      END
