      PROGRAM DUAL_ISO
      IMPLICIT NONE

C     Given dual groups for all groups, list of which groups might be
C     isomorphic and which not, creates a file that can be run in Magma
C     to decide, if the duals are isomorphic or not.

C     IN data_u: 0 marks start of definetely new cases, as does 3
C     1 marks old case, 2 propably old.
     
      INTEGER DATAU(7159),N,L,J,I,MAX
      INTEGER DATANB(7159)
      INTEGER K

C     Open the data file on units 3, and 4 
      OPEN (UNIT=3, FILE='data_u.txt')
      OPEN (UNIT=4, FILE='data_nb.txt')


C     Read in the data:

      MAX=7159

      READ (3,*) (DATAU(I), I=1,MAX)
      CLOSE(UNIT=3)

      READ (4,*) (DATANB(I), I=1,MAX)
      CLOSE(UNIT=4)


      WRITE(*,*) 'Data read ok'
      
C     Open the result file
      OPEN(UNIT=7, FILE='di_check.txt')

      N=1

 500  IF(N.LT.MAX) THEN
         N=N+1
         WRITE(*,*) N
         J=N-1
         L=DATANB(N)

         IF(DATAU(N) .EQ. 0 .OR. DATAU(N) .EQ. 3) THEN 
            GOTO 500
         END IF

         IF (DATAU(N) .EQ. 1 .OR. DATAU(N) .EQ. 2) THEN
 1000       K=DATANB(J)
            
            WRITE(7,'(A)') 'if IsIsomorphic('

            IF(L.LT.10) WRITE(7,'(A,I1,A)')'G', L, ','
            IF(L.GT.9 .AND. L.LT.100) THEN
               WRITE(7,'(A,I2,A)') 'G',L, ','
            END IF
            IF(L.GT.99 .AND. L.LT.1000) THEN
               WRITE(7,'(A,I3,A)') 'G',L, ','
            END IF
            IF(L.GT.999) THEN
               WRITE(7,'(A,I4,A)') 'G',L, ','
            END IF

            IF(K.LT.10) WRITE(7,'(A,I1,A)') 'G',K, ') then'
            IF(K.GT.9 .AND. K.LT.100) THEN
               WRITE(7,'(A,I2,A)') 'G',K, ') then'
            END IF
            IF(K.GT.99 .AND. K.LT.1000) THEN
               WRITE(7,'(A,I3,A)') 'G',K, ') then'
            END IF
            IF(K.GT.999) THEN
               WRITE(7,'(A,I4,A)') 'G',K, ') then'
            END IF

           IF(L.LT.10) WRITE(7,'(A,I1,A)') 'print ', L, ';'
            IF(L.GT.9 .AND. L.LT.100) THEN
               WRITE(7,'(A,I2,A)') 'print ',L, ';'
            END IF
            IF(L.GT.99 .AND. L.LT.1000) THEN
               WRITE(7,'(A,I3,A)') 'print ',L, ';'
            END IF
            IF(L.GT.999) THEN
               WRITE(7,'(A,I4,A)') 'print ',L, ';'
            END IF

            IF(K.LT.10) WRITE(7,'(A,I1,A)') 'print ',K, ';'
            IF(K.GT.9 .AND. K.LT.100) THEN
               WRITE(7,'(A,I2,A)') 'print ',K, ';'
            END IF
            IF(K.GT.99 .AND. K.LT.1000) THEN
                      WRITE(7,'(A,I3,A)') 'print ',K, ';'
            END IF
            IF(K.GT.999) THEN
               WRITE(7,'(A,I4,A)') 'print ',K, ';'
            END IF

            WRITE(7,'(A)') 'end if;'

            IF(DATAU(J) .EQ. 1 .OR. DATAU(J) .EQ. 2) THEN
               J=J-1
               GOTO 1000
            ELSE
               GOTO 500
            END IF
         END IF
         
      END IF         

 9999 END
