C
C Program CRT2P collecting 2-point rays from the unformatted output of
C program CRT.
C
C Version: 5.80
C Date: 2003, November 23
C
C Coded by: Ludek Klimes
C     Department of Geophysics, Charles University Prague,
C     Ke Karlovu 3, 121 16 Praha 2, Czech Republic,
C     E-mail: klimes@seis.karlov.mff.cuni.cz
C
C.......................................................................
C
C                                                    
C Description of data files:
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 CRT-R with the quantities stored along
C             rays, see
C             C.R.T.5.5.1,
C             or input file CRT-S with the quantities
C             stored at the specified surfaces, see
C             C.R.T.5.5.2.
C     'INIALL'... Input file CRT-I with the quantities at the initial
C             points of rays, corresponding to file RAYALL, see
C             C.R.T.6.1.
C     'RAY2P'... Output file CRT-R or CRT-S, with the quantities
C             corresponding to the 2-point rays only.
C     'INI2P'... Output file CRT-I with the quantities at the initial
C             points 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 description within source code file 'writ.for'.
C     Description of files CRT-R
C     Description of files CRT-S
C
C Unformatted files INIALL and INI2P:
C     See the description within source code file 'writ.for'.
C     Description of files CRT-I
C
C-----------------------------------------------------------------------
C
C Common block /POINTC/ to store the results of complete ray tracing:
      INCLUDE 'pointc.inc'
C     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,KMAH,
     *               X,UEBRAY,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 'error.for'
C     error.for
      INCLUDE 'length.for'
C     length.for
      INCLUDE 'ap.for'
C     ap.for
C
C=======================================================================
C