C
C     One-purpose code to read the tables QILST generated by program
C     green.for, and to generate the table comparing the results of
C     anisotropic common S wave ray tracing in model QI with the
C     quadratic perturbation from the isotropic ray.
C
C     Date: 2003, May 6
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) 'SEP'/
C     'SEP'...Name of the file with input parameters.
C             Description of file SEP
C             If blank, default values of the corresponding data are
C             considered.
C     No default, 'SEP' must be specified and cannot be blank.
C
C                                                     
C Input file 'SEP' in the SEP format:
C     The file has the form of a SEP parameter file.
C     For the description of the SEP format refer to file
C     'sep.for'.
C Names of input and output files:
C     QILSTI='string' ... Name of the input file containing
C             second-order perturbations of anisotropic travel times
C             of S waves calculated by isotropic ray tracing.
C             Default: QILSTI='qilsti.out'
C     QILSTA='string' ... Name of the input file containing
C             second-order perturbations of anisotropic travel times
C             of S waves calculated by anisotropic common ray tracing.
C             Default: QILSTA='qilsta.out'
C             
C             Description of files QILSTI and QILSTA.
C     QILSTC='string' ... Name of the output file containing
C             .
C             Default: QILSTC='qilstc.out'
C
C                                                  
C Output formatted file QILSTC with
C (1) / (a slash).
C (2) For each two-point ray (2.1):
C (2.1) IREC,TA,DTL,DTQ,DT,TI,T/
C     IREC... Number of the receiver corresponding to the two-point ray.
C     TA  ... Travel time of anisotropic S-wave common ray.
C     DTL ... Average first-order perturbation of travel time,
C             from the isotropic S-wave reference ray to the
C             anisotropic ray theory S1 and S2 rays.
C     DTQ ... Average second-order perturbation of travel time,
C             from the isotropic S-wave reference ray to the
C             anisotropic S-wave common reference ray.
C     DA  ... Travel time difference of
C     TA  ... Travel time of
C     TA  ... Travel time of
C     /...    A slash at the end of line.
C (3) / (a slash).
C
C-----------------------------------------------------------------------
C
      CHARACTER*80 FILSEP,FILEA,FILEI,FILEC
      REAL TC(999)
C
C     Reading name of SEP file with input data:
      WRITE(*,'(A)') '+QILST: Enter input filename: '
      FILSEP=' '
      READ(*,*) FILSEP
C
C     Reading all data from the SEP file into the memory:
      IF (FILSEP.NE.' ') THEN
        CALL RSEP1(1,FILSEP)
      ELSE
C       QILST-01
        CALL ERROR('QILST-01: SEP file not given')
C       Input file in the form of the SEP (Stanford Exploration Project)
C       parameter or history file must be specified.
C       There is no default filename.
      ENDIF
C
      WRITE(*,'(A)') '+QILST: Working ...           '
      CALL RSEP3T('QILSTI',FILEI,'qilsti.out')
      CALL RSEP3T('QILSTA',FILEA,'qilsta.out')
      CALL RSEP3T('QILSTC',FILEC,'qilstc.out')
C
      OPEN(1,FILE=FILEI)
      OPEN(2,FILE=FILEA)
      OPEN(3,FILE=FILEC)
      READ(1,*)
      READ(2,*)
      WRITE(3,'(A)') '/'
   10 CONTINUE
        I=0
        READ(2,*) I,TCI
        IF(I.EQ.0) GO TO 20
        TC(I)=TCI
      GO TO 10
   20 CONTINUE
   30 CONTINUE
        I=0
        READ(1,*) I,T0,T1,T2,D1,D2,Q1,Q2,Q0
        IF(I.EQ.0) GO TO 40
        T=0.5*(T1+T2)-Q0
        WRITE(3,'(I6,1X,F7.6,3(1X,F8.6),2(1X,F7.6),A)')
     *        I,T0,0.5*(D1+D2),0.5*(Q1+Q2)-Q0,TC(I)-T,TC(I),T,' /'
      GO TO 30
   40 CONTINUE
      WRITE(3,'(A)') '/'
      CLOSE(1)
      CLOSE(2)
      CLOSE(3)
      WRITE(*,'(A)') '+QILST: Done.                 '
      STOP
      END
C
C=======================================================================
C
      INCLUDE 'sep.for'
      INCLUDE 'error.for'
      INCLUDE 'length.for'
C
C=======================================================================
C