      PROGRAM LISTAUS
      IMPLICIT NONE

C     Lists the non-isomoprhic groups for the article

      INTEGER CUBEL(7159), PLACE(7159), N, MAX
      INTEGER CLIST(168), SUM, ISOCL(168) 
      INTEGER TRI(7159*19,3), V(7159,15)
      INTEGER JJ, KK, K, II, I, J, L, NN

C     Open the data file on units 3, 4 and 5
      OPEN (UNIT=3, FILE='T_list.txt')
      OPEN (UNIT=4, FILE='cubes.txt')
      OPEN (UNIT=5,FILE='classes.txt')
      OPEN (UNIT=7,FILE='isomcl.txt')
C      OPEN (UNIT=7, FILE='listing.txt')
      OPEN (UNIT=8, FILE='xlisting.txt')

C     Read in the data:

      MAX=7159
      WRITE(*,*) 'Start'

C Read in the number of cubes for each representative
      READ (4,*) (CUBEL(I), I=1,MAX)
      CLOSE(UNIT=4)

      I=1
      SUM=0
 15   IF (I.LE. MAX) THEN
         SUM=SUM+15+(CUBEL(I)+2)/3*2
         I=I+1
         GOTO 15
      END IF

      READ(5,*) (CLIST(I),I=1,168)
      CLOSE(UNIT=5)

      READ (3,*) ((TRI(I,J), J=1,3), I=1,SUM)
      CLOSE(UNIT=3)

      READ(7,*) (ISOCL(I),I=1,168)
      CLOSE(UNIT=7)

      OPEN (UNIT=3, FILE='x_list.txt')
      READ(3,*) ((V(I,J),J=1,15),I=1,MAX)
      CLOSE(UNIT=3)

      WRITE(*,*) 'Data read ok'

      WRITE(*,'(15I3)') ((V(I,J),J=1,15),I=1,30)
      
C Make list of the last rows of each group on T_list
      I=2
      PLACE(1)=0
 20   IF(I .LE. MAX) THEN
         PLACE(I)=PLACE(I-1)+15+((CUBEL(I-1)+2)/3)*2
         I=I+1
         GOTO 20
      END IF


      N=1
      OPEN (UNIT=7, FILE='listing.txt')

C For every group
 50   L=CLIST(N)

      WRITE(*,*) L
      WRITE(*,*) PLACE(L)

      NN=N+23
      I=ISOCL(N)

      IF(NN.GT.9 .AND. N .LT. 100) THEN 
         WRITE(7,'(A,I2,A,I1,A)') '$T_{',NN,'}$&(',I,')&'
         WRITE(8,'(A,I2,A,I1,A)') '$v_{',NN,'}$&(',I,')&'
      ELSE
         WRITE(7,'(A,I3,A,I1,A)') '$T_{', NN, '}$&(',I,')&'
         WRITE(8,'(A,I3,A,I1,A)') '$v_{', NN, '}$&(',I,')&'
      END IF

      WRITE(8,'(15(A,I2),A)') '$y_{', V(L,1), 
     +     '}$, $y_{', V(L,2), 
     +     '}$, $y_{', V(L,3), 
     +     '}$, $y_{', V(L,4), 
     +     '}$, $y_{', V(L,5), 
     +     '}$, $y_{', V(L,6), 
     +     '}$, $y_{', V(L,7), 
     +     '}$, $y_{', V(L,8), 
     +     '}$, $y_{', V(L,9), 
     +     '}$, $y_{', V(L,10), 
     +     '}$, $y_{', V(L,11), 
     +     '}$, $y_{', V(L,12), 
     +     '}$, $y_{', V(L,13), 
     +     '}$, $y_{', V(L,14), 
     +     '}$, $y_{', V(L,15),
     +     '}$\\'


C For every triangle
 100  DO 200 K=1,15+CUBEL(L)/3*2

      II=TRI(PLACE(L)+K,1)
      JJ=TRI(PLACE(L)+K,2)
      KK=TRI(PLACE(L)+K,3)

      IF(K.EQ. 15+CUBEL(L)/3*2) GOTO 150

      IF(II.LT.10.AND. JJ.LT.10.AND.KK.LT.10) THEN
         WRITE(7,'(A,I1,A,I1,A,I1,A)') '$x_',II,'x_',JJ,'x_',KK,'$,'
      ELSE IF(II.LT.10.AND. JJ.LT.10) THEN
         WRITE(7,'(A,I1,A,I1,A,I2,A)') '$x_',II,'x_',JJ,
     +        'x_{',KK,'}$,'
      ELSE IF(II.LT.10.AND. KK.LT.10) THEN
         WRITE(7,'(A,I1,A,I2,A,I1,A)') '$x_',II,'x_{',JJ,
     +        '}x_',KK,'$,'
      ELSE IF(JJ.LT.10.AND.KK.LT.10) THEN
         WRITE(7,'(A,I2,A,I1,A,I1,A)') '$x_{',II,'}x_',JJ,
     +        'x_',KK,'$,'
      ELSE IF(II.LT.10)THEN
         WRITE(7,'(A,I1,A,I2,A,I2,A)') '$x_{',II,'}x_{',JJ
     +        ,'}x_{',KK,'}$,'
      ELSE IF(JJ.LT.10) THEN
         WRITE(7,'(A,I2,A,I1,A,I2,A)') '$x_{',II,'}x_',JJ,
     +        'x_{',KK,'}$,'
      ELSE IF(KK.LT.10) THEN
         WRITE(7,'(A,I2,A,I2,A,I1,A)') '$x_{',II,'}x_{',JJ,
     +        '}x_',KK,'$,'
      ELSE
         WRITE(7,'(A,I2,A,I2,A,I2,A)') '$x_{',II,'}x_{',JJ,
     +        '}x_{',KK,'}$,'
      END IF
      GOTO 200

 150       IF(II.LT.10.AND. JJ.LT.10.AND.KK.LT.10) THEN
         WRITE(7,'(A,I1,A,I1,A,I1,A)') '$x_',II,'x_',JJ,'x_',KK,'$\\'
      ELSE IF(II.LT.10.AND. JJ.LT.10) THEN
         WRITE(7,'(A,I1,A,I1,A,I2,A)') '$x_',II,'x_',JJ,
     +        'x_{',KK,'}$\\'
      ELSE IF(II.LT.10.AND. KK.LT.10) THEN
         WRITE(7,'(A,I1,A,I2,A,I1,A)') '$x_',II,'x_{',JJ,
     +        '}x_',KK,'$\\'
      ELSE IF(JJ.LT.10.AND.KK.LT.10) THEN
         WRITE(7,'(A,I2,A,I1,A,I1,A)') '$x_{',II,'}x_',JJ,
     +        'x_',KK,'$\\'
      ELSE IF(II.LT.10)THEN
         WRITE(7,'(A,I1,A,I2,A,I2,A)') '$x_{',II,'}x_{',JJ
     +        ,'}x_{',KK,'}$\\'
      ELSE IF(JJ.LT.10) THEN
         WRITE(7,'(A,I2,A,I1,A,I2,A)') '$x_{',II,'}x_',JJ,
     +        'x_{',KK,'}$\\'
      ELSE IF(KK.LT.10) THEN
         WRITE(7,'(A,I2,A,I2,A,I1,A)') '$x_{',II,'}x_{',JJ,
     +        '}x_',KK,'$\\'
      ELSE
         WRITE(7,'(A,I2,A,I2,A,I2,A)') '$x_{',II,'}x_{',JJ,
     +        '}x_{',KK,'}$\\'
      END IF
      WRITE(7,'(A)') '   ' 


C      IF(K.EQ. 15+CUBEL(L)/3*2) GOTO 150
C
C      IF(II.LT.10.AND. JJ.LT.10.AND.KK.LT.10) THEN
C         WRITE(7,'(A,I1,A,I1,A,I1,A)') '$(x_',II,',x_',JJ,',x_',KK,')$,'
C      ELSE IF(II.LT.10.AND. JJ.LT.10) THEN
C         WRITE(7,'(A,I1,A,I1,A,I2,A)') '$(x_',II,',x_',JJ,
C     +        ',x_{',KK,'})$,'
C      ELSE IF(II.LT.10.AND. KK.LT.10) THEN
C         WRITE(7,'(A,I1,A,I2,A,I1,A)') '$(x_',II,',x_{',JJ,
C     +        '},x_',KK,')$,'
C      ELSE IF(JJ.LT.10.AND.KK.LT.10) THEN
C         WRITE(7,'(A,I2,A,I1,A,I1,A)') '$(x_{',II,'},x_',JJ,
C     +        ',x_',KK,')$,'
C      ELSE IF(II.LT.10)THEN
C         WRITE(7,'(A,I1,A,I2,A,I2,A)') '$(x_{',II,'},x_{',JJ
C     +        ,'},x_{',KK,'})$,'
C      ELSE IF(JJ.LT.10) THEN
C         WRITE(7,'(A,I2,A,I1,A,I2,A)') '$(x_{',II,'},x_',JJ,
C     +        ',x_{',KK,'})$,'
C      ELSE IF(KK.LT.10) THEN
C         WRITE(7,'(A,I2,A,I2,A,I1,A)') '$(x_{',II,'},x_{',JJ,
C     +        '},x_',KK,')$,'
C      ELSE
C         WRITE(7,'(A,I2,A,I2,A,I2,A)') '$(x_{',II,'},x_{',JJ,
C     +        '},x_{',KK,'})$,'
C      END IF
C      GOTO 200
C
C 150       IF(II.LT.10.AND. JJ.LT.10.AND.KK.LT.10) THEN
C         WRITE(7,'(A,I1,A,I1,A,I1,A)') '$(x_',II,',x_',JJ,',x_',KK,')$'
C      ELSE IF(II.LT.10.AND. JJ.LT.10) THEN
C         WRITE(7,'(A,I1,A,I1,A,I2,A)') '$(x_',II,',x_',JJ,
C     +        ',x_{',KK,'})$'
C      ELSE IF(II.LT.10.AND. KK.LT.10) THEN
C         WRITE(7,'(A,I1,A,I2,A,I1,A)') '$(x_',II,',x_{',JJ,
C     +        '},x_',KK,')$'
C      ELSE IF(JJ.LT.10.AND.KK.LT.10) THEN
C         WRITE(7,'(A,I2,A,I1,A,I1,A)') '$(x_{',II,'},x_',JJ,
C     +        ',x_',KK,')$'
C      ELSE IF(II.LT.10)THEN
C         WRITE(7,'(A,I1,A,I2,A,I2,A)') '$(x_{',II,'},x_{',JJ
C     +        ,'},x_{',KK,'})$'
C      ELSE IF(JJ.LT.10) THEN
C         WRITE(7,'(A,I2,A,I1,A,I2,A)') '$(x_{',II,'},x_',JJ,
C     +        ',x_{',KK,'})$'
C      ELSE IF(KK.LT.10) THEN
C         WRITE(7,'(A,I2,A,I2,A,I1,A)') '$(x_{',II,'},x_{',JJ,
C     +        '},x_',KK,')$'
C      ELSE
C         WRITE(7,'(A,I2,A,I2,A,I2,A)') '$(x_{',II,'},x_{',JJ,
C     +        '},x_{',KK,'})$'
C      END IF
C      WRITE(7,'(A)') '   ' 

 200  CONTINUE

      IF(N.LT. 168) THEN
         N=N+1
         GOTO 50
      ELSE
         WRITE(*,*) '168 tringle presentations written to listing.txt'
         GOTO 9999
      END IF

 9999 END
