C PROGRAM 'CRTRAY' CONVERTING THE UNFORMATTED OUTPUT OF PROGRAM 'CRT'
C INTO FORMATTED FILES WITH RAYS SUITABLE FOR PLOTTING.
C
C THIS SIMPLE CONVERSION PROGRAM MAY SERVE AS AN EXAMPLE HOW TO READ AND
C PROCESS OUTPUT FILES OF THE COMPLETE RAY TRACING PROGRAM 'CRT'.
C READING THE OUTPUT FILES IS COMPLETED BY A SIMPLE INVOCATION OF
C SUBROUTINE AP00 OF FILE 'AP.FOR'.
C
C THE STRUCTURE OF THE OUTPUT FILE WITH RAYS IS AN EXTENSION OF THE
C GENERAL FILE FORM 'LINES' DESCRIBED IN 'FORMS.DOC' AND DESIGNED TO
C STORE 3-D CURVES, E.G., FOR THE PURPOSES OF PLOTTING.
C
C MAIN INPUT DATA READ FROM EXTERNAL INTERACTIVE DEVICE (*):
C     THE DATA CONSIST OF THREE CHARACTER STRINGS, READ BY LIST DIRECTED
C     (FREE FORMAT) INPUT.  THUS THE STRINGS HAVE TO BE ENCLOSED
C     IN APOSTROPHES.  THE INTERACTIVE * EXTERNAL UNIT MAY BE REDIRECTED
C     TO THE FILE CONTAINING THE STRINGS.
C (1) 'RAYPOINTS','INITIALPOINTS','RAYS'
C     'RAYPOINTS'... FILE WITH THE QUANTITIES STORED ALONG RAYS (SEE
C             C.R.T.5.5.1).
C     'INITIALPOINTS'... FILE WITH THE QUANTITIES AT THE INITIAL POINTS
C             OF RAYS, CORRESPONDING TO FILE 'RAYPOINTS' (SEE
C             C.R.T.6.1).
C     'RAYS'..NAME OF THE OUTPUT FORMATTED FILE WITH RAYS.  THIS FILE IS
C             DESIGNED, FOR INSTANCE, AS INPUT FILE FOR PLOTTING RAYS.
C DEFAULT: 'RAYPOINTS'='R01.OUT', 'INITIALPOINTS'='R01I.OUT',
C     'RAYS'='RAYS.OUT'.
C
C INPUT UNFORMATTED FILE 'RAYPOINTS':
C     SEE THE DECRIPTION WITHIN SOURCE CODE FILE 'WRIT.FOR'.
C
C INPUT UNFORMATTED FILE 'INITIALPOINTS':
C     SEE THE DECRIPTION WITHIN SOURCE CODE FILE 'WRIT.FOR'.
C
C OUTPUT FORMATTED FILE 'RAYS':
C (1) / (A SLASH).
C (2) FOR EACH RECEIVER (2.1), (2.2), AND (2.3):
C (2.1) 'WAVENNNN, RAYNNNNN',/
C     'WAVENNNN, RAYNNNNN'... STRING IN APOSTROPHES, COMPOSED OF
C             SUBSTRING 'WAVE',
C             SEQUENTIAL INDEX OF THE ELEMENTARY WAVE, WRITTEN USING
C               FORMAT (I4),
C             SUBSTRING ', RAY',
C             SEQUENTIAL INDEX OF THE RAY WITHIN THE WAVE, WRITTEN USING
C               FORMAT (I5).
C     /...    AN OBLIGATORY SLASH AFTER THE STRING, IN PLACE OF THE
C             COORDINATES OF THE REFERENCE POINT.
C (2.2) FOR EACH POINT OF THE RAY (2.1.1):
C (2.2.1) X1,X2,X3,TT,/
C     X1,X2,X3... COORDINATES OF THE POINT OF THE RAY.
C     TT...   ARRIVAL TIME AT THE POINT.
C     /...    AN OBLIGATORY SLASH AFTER AT THE END OF LINE, IN PLACE
C             WHERE THE SLOWNESS VECTOR COMPONENTS COULD BE WRITTEN.
C (2.3) / (A SLASH).
C (3) / (A SLASH).
C
C DATE: 1994, JANUARY 23
C CODED BY LUDEK KLIMES
C
C-----------------------------------------------------------------------
C
C COMMON BLOCK /POINTC/ TO STORE THE RESULTS OF COMPLETE RAY TRACING:
      INTEGER IWAVE,IRAY,IPT,NYF,ICB1F,ISRFF,NY,ICB1,ISRF
      INTEGER ICB1I,IEND,ISHEET
      REAL XF,YLF(6),YF(39),X,YL(6),Y(39),YLI(6),YI(25)
      COMMON/POINTC/IWAVE,IRAY,IPT,NYF,ICB1F,ISRFF,XF,YLF,YF,
     *                 NY ,ICB1 ,ISRF ,X ,YL ,Y,ICB1I,IEND,ISHEET,YLI,YI
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:
      CHARACTER*80 FILE1,FILE2,FILE3
      INTEGER LU1,LU2,LU3
      PARAMETER (LU1=1)
      PARAMETER (LU2=2)
      PARAMETER (LU3=3)
C
C.......................................................................
C
C     OPENING INPUT AND OUTPUT FILES:
      FILE1='R01.OUT'
      FILE2='R01I.OUT'
      FILE3='RAYS.OUT'
      WRITE(*,'(2A)') ' ENTER ''RAYPOINTS'', ''INITIALPOINTS'',',
     *                                       ' AND ''RAYS'' FILENAMES: '
      READ(*,*) FILE1,FILE2,FILE3
      OPEN(LU1,FILE=FILE1,FORM='UNFORMATTED',STATUS='OLD')
      OPEN(LU2,FILE=FILE2,FORM='UNFORMATTED',STATUS='OLD')
      OPEN(LU3,FILE=FILE3)
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
        ELSE IF(IPT.LE.1)THEN
C         NEW RAY - RECORDING THE INITIAL POINT
          WRITE(LU3,'(A)')         '/'
          WRITE(LU3,'(A,I4,A,I5,A)') '''WAVE',IWAVE,', RAY',IRAY,''' /'
          WRITE(LU3,'(4F12.6,A)') YI(3),YI(4),YI(5),YI(1),' /'
        END IF
        WRITE(LU3,'(4F12.6,A)') Y(3),Y(4),Y(5),Y(1),' /'
      GO TO 10
C
   80 CONTINUE
      WRITE(LU3,'(A)') '/'
      WRITE(LU3,'(A)') '/'
      CLOSE(LU3)
      CLOSE(LU2)
      CLOSE(LU1)
      STOP
      END
C
C=======================================================================
C
