      PROGRAM PLOTXY

C     Plots central rays of beams generated by FIELD3D

      INTEGER RAYFIL, PRTFIL
      PARAMETER ( PRTFIL = 6, RAYFIL = 5 )

      REAL*4 X(10000), Y(10000), XV(10000), YV(10000)

      OPEN( FILE = 'RAYFIL', UNIT = RAYFIL, STATUS = 'OLD' )

      NBEAMS = 10000

C     *** Write data ***

      DO I = 1, NBEAMS
         READ( RAYFIL, *, END = 9000 ) NSTEPS

         DO ISTEP = 1, NSTEPS
           READ( RAYFIL, *, END = 9000 ) XV( ISTEP ), YV( ISTEP )
         ENDDO

         DO ISTEP = 1, NSTEPS
            X( ISTEP ) = XV( ISTEP ) / 1000.0
            Y( ISTEP ) = YV( ISTEP ) / 1000.0
            WRITE( PRTFIL, * ) X( ISTEP ), Y( ISTEP )
         END DO

         WRITE( PRTFIL, * ) X( NSTEPS ), Y( 1 )
         WRITE( PRTFIL, * ) X( 1      ), Y( 1 )

      END DO

 9000 STOP
      END
