      PROGRAM ANALYZE
      IMPLICIT NONE

C     Analyzes the given magma data about isomorphic dual pairs
     
      INTEGER DATAD(404526), NUNIQ(7159), NU(7159), DATANB(7159)
      INTEGER K, L, N, I, MAX, SUM, RMAX

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

C     Read in the data:

      MAX=7159
      RMAX=404526

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

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

      N=0
      SUM=0

 500  IF(N.LT.MAX) THEN
         N=N+1
         WRITE(*,*) N

         K=1
 600     IF(DATAD(2*K-1) .EQ. N) THEN
            NUNIQ(N)=DATAD(2*K)
            GOTO 500
         ELSE
            K=K+1
            IF(K .LE. RMAX/2) GOTO 600
         END IF
         
         NUNIQ(N)=0
         SUM=SUM+1
         GOTO 500
      END IF

 1000 DO 2000 N=1,MAX
         NU(N)=NUNIQ(DATANB(N))
 2000 CONTINUE

      WRITE(7,'(I4)') (NU(L), L=1,MAX)
      WRITE(*,*) SUM
 9999 END
