C                                                            <HTML><PRE>
C Program CRT for complete ray tracing
C
C Version: 5.10
C Date: 1997, October 25
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 This file consists of:
C     CRT...  Main program controlling the complete ray tracing.
C             <A HREF="#CRT">CRT</A>
C     LUWARN..Integer external function to remember the logical unit
C             number of the output file to write the warning messages.
C             <A HREF="#LUWARN">LUWARN</A>
C
C.......................................................................
C
C                                                    <A NAME="data"></A>
C Description of data files:
C
C Input data read from the * external unit:
C     The data consist of a single character string, read by list
C     directed (free format) input.  Thus the string has to be enclosed
C     in apostrophes.  The interactive * external unit may be redirected
C     to the file containing the string.
C (1) 'CRT'
C     The string containing the name of the main input data file for the
C     complete ray tracing program.  The data file 'CRT' will be read in
C     by the subroutine CRTIN, and is described within the FORTRAN77
C     source code file 'crtin.for'.  Only the first 80 characters of the
C     string are significant.
C     <A HREF="crtin.for#data">Description of data file CRT</A>
C Default: 'CRT'='crt.dat'.
C
C=======================================================================
C
C     <A NAME="CRT"></A>
C
      PROGRAM CRT
C
C Main program for complete ray tracing.  This program reads the input
C data and then controls the complete ray tracing of the specified
C elementary waves.
C
C Input data: Main input data set containing the names of other input
C files and the name of the output log file is read in by the subroutine
C CRTIN of the file 'crtin.for'.  Thus, the structure of the main input
C data set is described in the file 'crtin.for'.
C The name of the main input data file is given by the first actual
C argument of the subroutine crtin called in the first executive
C statement of the main program.  It is blank in the original version.
C
C Subroutines referenced:
      EXTERNAL CRTIN,RAY2,INIT2,CODE1,RPAR1,RPAR2,RPAR4
      EXTERNAL WRIT1,WRIT2,WRIT4,WRIT5
C     MODEL1...File  'model.for' of the package 'model'.
C     CRTIN,UNIT... File 'crtin.for'.
C     RAY1,RAY2... File 'ray.for'.
C     INIT1,INIT2... File 'init.for'.
C     CODE1... File 'code.for'.
C     RPAR1,RPAR2,RPAR4... File 'rpar.for'.
C     WRIT1,WRIT2,WRIT4, WRIT5... File 'writ.for'.
C Note that the above subroutines reference many other external
C procedures from various subroutine files.  These indirectly
C referenced procedures are not named here, but are listed in the
C particular subroutine files.
C
C Date: 1997, July 21
C Coded by Ludek Klimes
C
C-----------------------------------------------------------------------
C
C     Storage locations:
C
C     Input data:
      CHARACTER*80 FCRT
C     FCRT... Name of the main input data file for the complete ray
C             tracing program.
C
C     Logical unit numbers:
      INTEGER LUCODE,LURPAR,LUWRIT,LULOG
C
C     LUCODE..The logical unit connected to the file with the CODE data.
C     LURPAR..The logical unit connected to the file with the RPAR data.
C     LUWRIT..The logical unit connected to the file with the WRIT data.
C     LULOG...The logical unit connected to the output LOG file.
C
C     Quantities describing elementary waves and their rays:
      REAL PAR1,PAR2,YL(6),Y(35),YY(5)
      INTEGER IWAVE,IWAVE0,IKODE,IRAY,IY(12),IEND,ISHEET,IREC
C
C     IWAVE...Index of the computed elementary wave.
C     IWAVE0..Index of the already computed elementary wave having the
C             most numerous common elements with the current elementary
C             wave.
C     IKODE...The length of the common part of the codes of the IWAVE-th
C             and IWAVE0-th elementary waves.
C     IRAY... Index of the computed ray.
C     PAR1,PAR2... Ray take-off parameters.
C     YL...   Array containing local quantities at a point of a ray (see
C             C.R.T.5.5.4).  The quantities are listed in the subroutine
C             file 'ray.for'.
C             <A HREF="ray.for#YL">Description of YL</A>
C     Y...    Array containing basic quantities computed along a ray
C             (see C.R.T.5.2.1).  The quantities are listed in the
C             subroutine file 'ray.for'.
C             <A HREF="ray.for#Y">Description of Y</A>
C     YY...   Array containing real auxiliary quantities computed along
C             a ray (see C.R.T.5.2.2).  The quantities are listed in the
C             subroutine file 'ray.for'.
C             <A HREF="ray.for#YY">Description of YY</A>
C     IY...   Array containing integer auxiliary quantities computed
C             along a ray (see C.R.T.5.2.2).  The quantities are listed
C             in the subroutine file 'ray.for'.
C             <A HREF="ray.for#IY">Description of IY</A>
C     IEND... Reason of the termination of the computation of a ray (see
C             C.R.T.5.4).
C             <A HREF="ray.for#IEND">Description of IEND in RAY2</A>
C             <A HREF="init.for#IEND">Description of IEND in INIT2</A>
C     ISHEET..Ray-history index.  The different ray histories are
C             consecutively indexed by positive integers 1,2,3,...
C             According to their appearance during ray tracing.
C             The ray histories are indexed independently within each
C             elementary wave.
C             The ray-history indices are complemented with sign:
C             Positive - successful ray (crossing reference surface),
C             negative - unsuccessful ray (terminating before crossing
C             reference surface).
C     IREC... Index of the receiver for a two-point ray, determined in
C             subroutine <A HREF="rpar.for#IREC">RPAR4</A>.
C
C.......................................................................
C
C     Opening data files and reading the input data:
C
      FCRT='crt.dat'
      WRITE(*,'(A)') ' Enter the name of the main input data file:'
      READ(*,*) FCRT
      WRITE(*,'(A)') '+Reading input data.                        '
      CALL CRTIN(FCRT,LUCODE,LURPAR,LUWRIT,LULOG)
      LULOG=LUWARN(LULOG)
      WRITE(*,'(A)') '+Computing.                                 '
C
C.......................................................................
C
C     Complete ray tracing:
C
      CALL WRIT1(LUWRIT,LULOG,0,0,0)
      IWAVE=0
      IRAY=0
C
C     Loop over elementary waves
   30 CONTINUE
C       Computation of a single elementary wave:
C       Reading the input data for the elementary wave
        CALL CODE1(LUCODE,IWAVE,IWAVE0,IKODE)
        IF(IWAVE.EQ.0) THEN
C         All required elementary waves are computed
          GO TO 90
        END IF
        CALL RPAR1(LURPAR,IWAVE)
        CALL WRIT1(LUWRIT,LULOG,IWAVE,IWAVE0,IKODE)
C       Loop over rays
   40   CONTINUE
C         Complete tracing of a single ray:
C         Determination of the take-off parameters
          CALL RPAR2(IRAY,PAR1,PAR2)
          IF(IRAY.EQ.0) THEN
C           All required rays of the elementary wave are computed
            GO TO 80
          END IF
C         Initial conditions for the ray
          CALL INIT2(PAR1,PAR2,YL,Y,YY,IY,IEND,IWAVE0,IKODE)
          CALL WRIT2(LULOG,IRAY)
          IF(IEND.EQ.0) THEN
C           Computation of the ray
            CALL RAY2(YL,Y,YY,IY,IEND)
          END IF
C         The ray is computed
          CALL RPAR4(IRAY,PAR1,PAR2,YL,Y,YY,IY,IEND,ISHEET,IREC)
          CALL WRIT4(LULOG,IRAY,YL,Y,YY,IY,IEND,ISHEET,IREC)
        GO TO 40
   80   CONTINUE
C       The elementary wave is computed
        CALL WRIT5(LULOG,IWAVE)
      GO TO 30
   90 CONTINUE
C
C     End of computation
      CALL WRIT5(LULOG,0)
      STOP
      END
C
C=======================================================================
C
C     <A NAME="LUWARN"></A>
C
      INTEGER FUNCTION LUWARN(LU)
      INTEGER LU
C
C Function to remember the logical unit number of the output file to
C write the warning messages.
C
C Input:
C     LU...   Positive logical unit number of the output file to write
C             the warning messages during the first invocation,
C             performed usually from the main program.
C             Otherwise zero.
C Output:
C     LUWARN..Logical unit number of the output file to write the
C             warning messages.
C             For consistency, it is recommended that the warning
C             message starts with string 'Warning' at the begining of
C             the first written line.  Numbered warnings should be
C             listed in the list of errors.
C
C Date: 1997, July 21
C Coded by Ludek Klimes
C
C-----------------------------------------------------------------------
C
      INTEGER LUSTOR
      SAVE    LUSTOR
C
      IF(LU.GT.0) THEN
        LUSTOR=LU
      END IF
      LUWARN=LUSTOR
      RETURN
      END
C
C=======================================================================
C
      INCLUDE 'model.for'
C     <A HREF="../model/model.for">model.for</A>
      INCLUDE 'metric.for'
C     <A HREF="../model/metric.for">metric.for</A>
      INCLUDE 'srfc.for'
C     <A HREF="../model/srfc.for">srfc.for</A>
      INCLUDE 'parm.for'
C     <A HREF="../model/parm.for">parm.for</A>
      INCLUDE 'val.for'
C     <A HREF="../model/val.for">val.for</A>
      INCLUDE 'fit.for'
C     <A HREF="../model/fit.for">fit.for</A>
      INCLUDE 'means.for'
C     <A HREF="../model/means.for">means.for</A>
      INCLUDE 'hpcg.for'
C     <A HREF="../model/hpcg.for">hpcg.for</A>
      INCLUDE 'crtin.for'
C     <A HREF="crtin.for">crtin.for</A>
      INCLUDE 'code.for'
C     <A HREF="code.for">code.for</A>
      INCLUDE 'ray.for'
C     <A HREF="ray.for">ray.for</A>
      INCLUDE 'raycb.for'
C     <A HREF="raycb.for">raycb.for</A>
      INCLUDE 'trans.for'
C     <A HREF="trans.for">trans.for</A>
      INCLUDE 'coef.for'
C     <A HREF="coef.for">coef.for</A>
      INCLUDE 'init.for'
C     <A HREF="init.for">init.for</A>
      INCLUDE 'rpar.for'
C     <A HREF="rpar.for">rpar.for</A>
      INCLUDE 'rp2d.for'
C     <A HREF="rp2d.for">rp2d.for</A>
      INCLUDE 'rp3d.for'
C     <A HREF="rp3d.for">rp3d.for</A>
      INCLUDE 'writ.for'
C     <A HREF="writ.for">writ.for</A>
C
C <A NAME="SCRO"></A><FONT COLOR="RED">Screen output subroutines:</FONT>
C Include just one of the following files 'scro*.for':
C (a) No report on the progress of calculation:
*     INCLUDE 'scronul.for'
C     <A HREF="scronul.for">scronul.for</A>
C (b) Very brief text screen output (indices of traced rays):
      INCLUDE 'scronum.for'
C     <A HREF="scronum.for">scronum.for</A>
C (c) More informative both text and graphical screen output:
*     INCLUDE 'scropc.for'
C     <A HREF="scropc.for">scropc.for</A>
C     Note that 'scropc.for' must be supplemented with CalComp graphics
C     subroutines PLOTS, PLOT, and NEWPEN designed for the particular
C     operating system and compiler.
C     <A HREF="scropc.for#CalComp">Required CalComp subroutines</A>
C     To disable screen graphics:
*     INCLUDE 'plotnul.for'
C     <A HREF="plotnul.for">plotnul.for</A>
C
C=======================================================================
C                                                                 </PRE>
