C PROGRAM 'CRT' FOR COMPLETE RAY TRACING
C
C BY VLASTISLAV CERVENY, LUDEK KLIMES, IVAN PSENCIK
C
C THIS FILE CONSISTS OF:
C     CRT...  MAIN PROGRAM CONTROLING THE COMPLETE RAY TRACING.
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 DEFAULT: 'CRT'='CRT.DAT'.
C
C=======================================================================
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: 1994, JANUARY 8
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
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     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     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     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     IEND... REASON OF THE TERMINATION OF THE COMPUTATION OF A RAY (SEE
C             C.R.T.5.4).
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
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)
      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)
          CALL WRIT4(LULOG,IRAY,YL,Y,YY,IY,IEND,ISHEET)
        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
