C Program 'crt2p' collecting 2-point rays from the unformatted output of
C program 'CRT'.
C
C Main input data read from external interactive device (*):
C     The data consist of character strings, read by list directed (free
C     format) input.  The strings have thus to be enclosed in
C     apostrophes.  The interactive * external unit may be redirected to
C     the file containing the data.
C (1) 'RAYALL','INIALL','RAY2P','INI2P',/
C     'RAYALL'... Input file with the quantities stored along rays (see
C             C.R.T.5.5.1).
C     'INIALL'... Input file with the quantities at the initial points
C             of rays, corresponding to file 'RAYALL' (see C.R.T.6.1).
C     'RAY2P'... Output file with the quantities stored along 2-point
C             rays (see C.R.T.5.5.1).
C     'INI2P'... Output file with the quantities at the initial points
C             of 2-point rays, corresponding to file 'RAY2P' (see
C             C.R.T.6.1).
C Default: 'RAYALL'='r01.out', 'INIALL'='r01i.out',
C     'RAY2P'='ray2p.out', 'INI2P'='ini2p.out'.
C
C Unformatted files 'RAYALL' and 'RAY2P':
C     See the decription within source code file 'writ.for'.
C
C Unformatted files 'INIALL' and 'INI2P':
C     See the decription within source code file 'writ.for'.
C
C Date: 1996, April 4
C Coded by Ludek Klimes
C
C-----------------------------------------------------------------------
C
C Common block /POINTC/ to store the results of complete ray tracing:
      INCLUDE 'pointc.inc'
C None of the storage locations of the common block are altered.
C
C Subroutines and external functions required:
      EXTERNAL AP00
C     AP00... File 'ap.for'.
C
C-----------------------------------------------------------------------
C
C     Auxiliary storage locations:
      INTEGER LU1,LU2,LU3,LU4,I
      PARAMETER (LU1=1,LU2=2,LU3=3,LU4=4)
      CHARACTER*80 FILE1,FILE2,FILE3,FILE4
C
C.......................................................................
C
C     Opening input and output files:
      FILE1='r01.out'
      FILE2='r01i.out'
      FILE3='ray2p.out'
      FILE4='ini2p.out'
      WRITE(*,'(2A)')
     *  ' Enter 4 filenames (r01.out, r01i.out, ray2p.out, ini2p.out): '
      READ(*,*) FILE1,FILE2,FILE3,FILE4
      OPEN(LU1,FILE=FILE1,FORM='UNFORMATTED',STATUS='OLD')
      OPEN(LU2,FILE=FILE2,FORM='UNFORMATTED',STATUS='OLD')
      OPEN(LU3,FILE=FILE3,FORM='UNFORMATTED')
      OPEN(LU4,FILE=FILE4,FORM='UNFORMATTED')
C
C     Loop for the points of rays
   10 CONTINUE
C       Reading the results of the complete ray tracing
        CALL AP00(0,LU1,LU2)
        IF(IWAVE.LT.1)THEN
C         End of rays
          GO TO 80
        END IF
        IF (IREC.GT.0) THEN
C         Two-point ray:
          WRITE(LU3) IWAVE,IRAY,NY,ICB1,ISRF,X,YL,(Y(I),I=1,NY)
          IF(IPT.LE.1)THEN
C           New ray - recording the initial point
            WRITE(LU4) -IWAVE,IRAY,ICB1I,IEND,ISHEET,IREC,YLI,YI
          END IF
        END IF
      GO TO 10
C
   80 CONTINUE
      CLOSE(LU1)
      CLOSE(LU2)
      CLOSE(LU3)
      CLOSE(LU4)
      STOP
      END
C
C=======================================================================
C
      INCLUDE 'ap.for'
C
C=======================================================================
C
