      IMPLICIT REAL*8 (A-H,O-Z)
      CHARACTER*5 SCHNAM
      CHARACTER*10 HMNAME
      CHARACTER*2 NP,NPO
      DIMENSION KB(3),KBB(3),KBC(3),KKB(3,10),KG(3,10)
      DIMENSION ICP(12,12),ICPP(12,12),ITCR(12)
      DIMENSION NDES(12),JTRS(12),IPAS(12)
      Character*80 InFile

! For Watcom Fortran
!       If(nArgs() .le. 1) Then
! For g77
      If(IArgC() .lt. 1) Then
         Write(*, '(a)') ' ******  Fatal Error ******'
         Write(*, '(a)') '  Input file must be specified'
         Stop 9999
      EndIf
! For Watcom Fortran
!       Call GetArg(1, InFile, iStat)
! For g77
       Call GetArg(1, InFile)
      OPEN(1,FILE=InFile,iostat=ISO,STATUS='OLD')

      OPEN(3,FILE='generator',iostat=ISO,STATUS='OLD')
C      OPEN(3,FILE='generator',iostat=ISO,STATUS='OLD')
C      WRITE(6,*) ISO
C      IF(ISO.NE.0) STOP
      READ(1,*) NUMBER
      IF(NUMBER.EQ.0) STOP
      CALL TSNTNM(NUMBER,3,NC,SCHNAM,HMNAME)
      NNC=1
      CALL TSPNGE(NUMBER,NNC,3)
      READ(1,*) A,B,C
      READ(1,*) CA,CB,CC
      CALL TSLATC(A,B,C,CA,CB,CC)
      READ(1,*) KX1,KY1,KZ1,IC1
      READ(1,*) KX2,KY2,KZ2,IC2
      READ(1,*) NPOINT
      IC=IC1*IC2*NPOINT
      ICC=IC
      DO 20 IW=1,2
      IWW=IW-1
      NPO="  "
      MMGO=0
      WRITE(6,*)
      IF(IWW.EQ.0) WRITE(6,*) ' SINGLE REPRESENTATION'
      IF(IWW.EQ.1) WRITE(6,*) ' DOUBLE REPRESENTATION'
      DO 91 IN=0,NPOINT
      KX=KX1*IC2*NPOINT+IN*(KX2*IC1-KX1*IC2)
      KY=KY1*IC2*NPOINT+IN*(KY2*IC1-KY1*IC2)
      KZ=KZ1*IC2*NPOINT+IN*(KZ2*IC1-KZ1*IC2)
      CALL KPNAME(KX,KY,KZ,IC,NP)
      CALL TSKFBZ(KX,KY,KZ,IC,IND)
      WRITE(6,600) NP,KX,KY,KZ,IC,IND
  600 FORMAT(' NAME OF K-POINT ',A2,3I3,'/',I3,I5)
      KB(1)=KX
      KB(2)=KY
      KB(3)=KZ
      CALL TSIREP(KB,IC,IWW)
      CALL DGTRMD(JDUB,NRS,MMG,NSTR,NDES,MTRR,JTRS,IPAS)
      IF(IN.NE.0.AND.(MMG.EQ.MMGO.AND.NP.EQ.NPO)) GO TO 90
      WRITE(6,607) MMG,NSTR,NRS,MTRR
  607 FORMAT(' ORDER OF K-POINT GROUP=',I3,' NUMBER OF STAR=',I3
     &      /' NUMBER OF REPRESENTATION=',I3
     &      /' NUMBER OF TIME REV. ELEM',I3)
      WRITE(6,608) (I,I=1,NRS)
      WRITE(6,604) (NDES(I),I=1,NRS)
      WRITE(6,605) (JTRS(I),I=1,NRS)
      WRITE(6,606) (IPAS(I),I=1,NRS)
  608 FORMAT('    NO      ',12I4)
  604 FORMAT(' DEGENERACY ',12I4)
  605 FORMAT(' HERRING SUM',12I4)
  606 FORMAT(' PARTNER NO ',12I4)
      IF(IN.EQ.0) GO TO 90
      IF(MMG.NE.MMGO.OR.MTRR.NE.MTRRO) THEN
         IF(MMG.LT.MMGO
     &      .OR.(MMG.EQ.MMGO.AND.MTRR.LT.MTRRO)) THEN
            CALL COMPAT(KB,IC,NR,KBB,ICC,NRT,IWW,ICP,INDC)
            CALL CMPTRV(KB,IC,KBB,ICC,IWW,ICP,ICPP)
         ELSE IF(MMG.GT.MMGO
     &      .OR.(MMG.EQ.MMGO.AND.MTRR.GT.MTRRO)) THEN
            CALL COMPAT(KBB,IC,NR,KB,ICC,NRT,IWW,ICP,INDC)
            CALL CMPTRV(KBB,IC,KB,ICC,IWW,ICP,ICPP)
         END IF
         WRITE(6,*) " COMPATIBILITY TABLE"
         WRITE(6,603) (JR,JR=1,NRT)
  603    FORMAT(5X,12I3)
         DO 21 IR=1,NR
         WRITE(6,602) IR,(ICP(JR,IR),JR=1,NRT)
  602    FORMAT(I3,2X,12I3)
   21    CONTINUE
         WRITE(6,*) ' WITH TIME REVERSAL SYMMETRY'
         DO 22 IR=1,NR
         WRITE(6,602) IR,(ICPP(JR,IR),JR=1,NRT)
   22    CONTINUE
      END IF
   90 CONTINUE
      IF(IND.EQ.0.AND.NPO.NE.NP) THEN
         CALL NEAREC(KB,IC,KKB,KG,NG)
         KBC(1)=KKB(1,1)
         KBC(2)=KKB(2,1)
         KBC(3)=KKB(3,1)
         CALL CORRES(KB,IC,KBC,ICC,IWW,ITCR,NRR,INDR)
         WRITE(6,609) KBC,ICC
  609    FORMAT(" CORRESPONDENCE TABLE TO",3I3,'/',I3) 
         WRITE(6,602) INDR,(ITCR(IR),IR=1,NRR)
         GO TO 32
   31    CONTINUE
   32    CONTINUE
      END IF
      KBB(1)=KX
      KBB(2)=KY
      KBB(3)=KZ
      NPO=NP
      MMGO=MMG
      MTRRO=MTRR
   91 CONTINUE
   20 CONTINUE
      pause
      STOP
      END
