C   01/11/84 809101248  MEMBER NAME  RDMTCO9  (JADEGS)      FORTRAN
C
C-----------------------------------------------------------------------
      SUBROUTINE RDMTCO( HOPT )
C-----------------------------------------------------------------------
C
C   AUTHOR:     E. ELSEN     4/05/79 :  PROCESSES THE MC CONSTANTS BANKS
C
C        MOD:   E. ELSEN    16/11/81 :
C        MOD:   C. BOWDERY   6/10/83 :  CREATE 'JETC'/9 BANK
C        MOD:   J. OLSSON   15/12/83 :  CORR. OF CTR123 ERROR
C        MOD:   J. HAGEMANN 11/10/83 :  VERTEX CHAMBER CODE
C               R. RAMCKE
C        MOD:   J.H.  C.B.  12/10/84 :  FIX-UP OF ROTNK & OTHER CHANGES
C        MOD:   J. HAGEMANN 08/11/84 :  COMMON /CVCEX/ IMPLEMENTED
C        MOD:   J. HAGEMANN 22/05/86 :  UPDATED CODE FOR CHANGING THE
C                                       INPUT FILE (SMEARED DATA <-->
C                                       UNSMEARED DATA) LIKE IN GRAPHICS
C                                       PROGRAM
C        MOD:   J. HAGEMANN 16/06/86 :  UPDATED VTXC BANK NUMBER
C        MOD:   J. OLSSON 7-8/86 :  GENERAL UPDATE TOGETHER WITH
C               OTHER TRIGGER ROUTINES. CALL PRAGAI, TO PREVENT
C               UNNECESSARY AND REPEATED PRINT
C               MOVE BLOCK DATA TO RDTRIG
C        MOD:   E. ELSEN    11/12/87 :  FOR NEW SMEARING SCHEMES IN
C               J. HAGEMANN             ID AND VTXC
C   LAST MOD:   J. OLSSON   25/07/88 :  NFLAGS(3) RESET FOR UNSMEARED
C                                       CALLS
C
C    THIS ROUTINE PROCESSES THE JET CHAMBER/VERTEX CHAMBER MC CONSTANTS
C    FOUND IN THE FIRST RECORD OF A MC EVENT DATASET. IT ACCOMMODATES
C    THE NEW INNER DETECTOR SMEARING SCHEME, SAVES THE CONSTANTS OF THIS
C    SCHEME IN THE START RECORD (MTCO EVENT) AND KEEPS COMPATIBILITY
C    WITH EARLIER MC DATA, WHICH ARE SMEARED IN A DIFFERENT WAY.
C
C    FURTHER CHANGES WERE INTRODUCED BY J.OLSSON, TO KEEP INFORMATION
C    ABOUT DOUBLE HIT RESOLUTION, RANDOM HITS AND EFFICIENCIES. THIS
C    WAS MADE BY STORING VALUES INTO MTCO IN SUBR. EVWRIT AND MARKING
C    MTCO, WORD 2.
C
C     IDATA(IPMTCO + 2) = FLAG FOR MTCO STORAGE OF SMEARING INFO.
C                A)   = 0  THIS INFORMATION WAS NOT KEPT
C                B)   = 1  INFORMATION IS KEPT, STORED IN MTCO
C
C
C    RDMTCO IS CALLED BY THE EVENT READING ROUTINE WHENEVER A
C    CALIBRATION EVENT WITH THE BANK MTCO IS ENCOUNTERED. SUCH AN
C    EVENT NORMALLY SHOULD CONTAIN THE BANKS MTCO,MJET AND MGEO. IT
C    MAY ALSO CONTAIN AN MVCC AND AN MGEV BANK WITH VERTEX CHAMBER
C    CONSTANTS.
C
C    RDMTCO COPIES THE CONSTANTS IN THESE BANKS INTO THE RELEVANT
C    COMMONS. RDMTCO ALSO INITIALISES THE SMEARING OF THE INNER DETECTOR
C
C      THERE ARE TWO OPTIONS FOR SMEARING THE DRIFT DATA
C       1. HOPT='DE'      DEFAULT VALUES FOR DRIFT TIME BINS AND
C                         Z AMPLITUDES ARE INSERTED.
C                         /CBIN/ IS OVERWRITTEN
C       2. HOPT='SE'      THE USER HAS TO PROVIDE PHI AND Z BINNING
C                         THROUGH THE COMMON/CBIN/
C      CBIN WILL HOWEVER BE OVERWRITTEN IN EITHER CASE IF THE
C      LAST MTCO BANK HAD THE SMEAR FLAG
C             IDATA(IDATA(IBLN('MTCO'))+1) .EQ. 1.
C
C  NOTE:
C  THESE DISTINCTIONS ARE HISTORICAL AND MEAN NOTHING. ALL PROGRAMS
C  CALL RDMTCO WITH 'DE' OPTION.
C
C
C     THE DETECTOR STATUS IS COPIED FROM MTCO INTO /CRDSTA/ AND /CTRIGG/
C     IF WORD2 IN MTCO IS NONZERO.
C
C     THE NEW SUBROUTINE RDRESO SETS FLAG ISMEAR IN /CADMIN/
C     FOR SMEARED DATA, ISMEAR IS SET = THIRD WORD IN MTCO
C     IF THIS FLAG IS SET, EVWRIT WILL STORE INFORMATION IN MTCO
C                  ***********
C     IPMTCO IS POINTER OF 'MTCO' - BANK
C
C     IDATA(IPMTCO + 3) = FLAG FOR SMEARING SCHEME
C                A)   = 0  O L D  SUBROUTINE RDRESO WAS USED
C                B)   = 1  N E W  SUBROUTINE RDRESO WAS USED
C
C     (IDATA(IPMTCO + 3 + I), I=1,6) = ACTUAL BINNING USED FOR SMEARING
C                                      OF INNER DETECTOR DRIFT DATA
C                                      (BINDL8(I), I=1,6)
C     IDATA(IPMTCO + 10)  =  STANDARD SMEARING OF DRIFT COORDINATE
C                            (RJITT)
C
C
C
C-----------------------------------------------------------------------
C
      IMPLICIT INTEGER * 2 (H)
C
      LOGICAL  LVTXC
C
#include "cmubcs.for"
C
      COMMON / CGEO1  / IGEO(66)
C
      EQUIVALENCE  ( IGEO(23), ROTNK )
C
      COMMON / CPRINT / NPRINT
      COMMON / CJDRCH / DRCH(34),
     +                  PEDES, TZERO(3),
     +                  DRIROT(96,2), SINDRI(96,2), COSDRI(96,2),
     +                  DRIVEL(96,2)
C
C                                          VERTEX CHAMBER
C
      COMMON / CVCEX  / LVTXC
      COMMON / CGEOV  / GEOV(13)
      COMMON / CJVTXC / VXCC(15),
     +                  DRILOR(24), SNLORA(24), CSLORA(24),
     +                  DRVELO(24)
      COMMON / CBINV /  DTRSVV, ZRSVV, EFFVV(2), DOUBVV(3), IRNHVV,
     +                  SMPRMV(3)
      DIMENSION ABINV(11)
      EQUIVALENCE ( ABINV(1), DTRSVV )
C
      COMMON / CADMIN / IEVTP,DUMM(6),ISMEAR,IJETCI,NFLAGS(10)
C
      COMMON / CRDSTA / NDEAD, NCDEAD, HITD(10), HCELLD(10), IPHALG
C
      COMMON /CTRIGG/ IHIST(3),NBPTFW,TAGADC,IDUM1(4),HDUM1,
     *  HLGBRT,HLGBST,HLGQT,HLGTOT(4,2),HECAPT(4),HLGTL,HLGTH,HTGTRG,
     *                HDUM2(9),IWIDBS,NRNBSL,NRNBSH,NTOFBS,IDUM2(10),
     *                NTOFC,NTOFC1,NTOFC2,NTBGC,NTBGC1,NTBGC2,
     *                IWCOLL,IWCOLN,IWMPRG,HFMPRL,HFMPRH,HWCOLN,HMPRON,
     *                IWCTBG,NTFCOL,NTFCLN,NTFBS2,IDUM3(9),
     *  HITCLL(3),HITWLL(3),HITSUM(3),HCHAMB(3),HMASK(16,3),HDEADC(10),
     *  HACC1,HACC2,HACC3,HACC4,HACCM,HDUM6,IWIDT2,HACCB1,HACCB2,
     *  HT1ACC,HT1PSP,IDUM4(8)
C
      DIMENSION TSTAT1(110), TSTAT2(13)
      EQUIVALENCE (TSTAT1(1),IHIST(1)), (TSTAT2(1), NDEAD)
C     COMMON / CTR123 / NPRINT,
C    +                  NBPTFW, NTOFC, IWCOLL, NTOFCA, ETOT1, ETOT2,
C    +                  ETOT3, HLGBRT, HLGQT, HLGET(4), HLGTL, HLGTH,
C    +              HITCLL(3),HITWLL(3),HITSUM(3),HCHAMB(3),HMASK(16,3),
C    +              HDEADC(10),HJTOF,HACC1,HACC2,HACC3,
C    +              HACC4,HFMPRL,HFMPRH,HMPRON,IWMPRG,
C    +              HACC5,HWCOLN,HFSCLL,HFSCLH,IWCOLN,IWIDT2
      DIMENSION TSTAT3(56),HSTAT3(112),ISTAT3(56)
      DIMENSION TSTAT4(13),HSTAT4(26),ISTAT4(13)
      EQUIVALENCE (TSTAT3(1),ISTAT3(1)),(ISTAT3(1),HSTAT3(1))
      EQUIVALENCE (TSTAT4(1),ISTAT4(1)),(ISTAT4(1),HSTAT4(1))
C
CCC USER SUPPLIED COMMON/CBIN/
C
      COMMON / CBIN   / TIME(6),ZOF,ZRS,ZL,ZSC,EPSI(3),DOUB(3),IRN(3),
     +                BINDL8(6),RJITT, DLRSLN(3), DLZSLN(3)
      DIMENSION ABIN(29)
      EQUIVALENCE ( ABIN(1), TIME(1) )
C
CCC /CBINMC/ IS USED FOR PASSING THE BINMC ARRAY TO SUBR. RDRDMH
C             THIS HAS HISTORICAL REASONS ONLY...
C
      COMMON / CBINMC / BINMC(6)
      DIMENSION SDRCH(34), SBIN(29), SBINV(11)
      DIMENSION IDOUBL(3)
C
C
      DATA SDRCH   / 34*0. /
      DATA SBIN    / 29*0. /
      DATA SBINV   / 11*0. /
      DATA IDOUBL  /  3*0  /
C
CCC   DATA HOPT1   / 'DE'  /
      DATA ICALL   /   0   /
      DATA IFLAG1  /   0   /
      DATA LBIN    /  29   /
      DATA LBINV   /  11   /
C
C-------------------  C O D E  -----------------------------------------
C
      ICALL = ICALL + 1
      IF( ICALL .EQ. 1) WRITE(6,6110)
6110  FORMAT(' ---> RDMTCO: VERSION FROM  JULY 1988')
C
CCC  CHECK IF CONSTANTS BANK IN BCS COMMON
C
      IPMTCO = IDATA( IBLN( 'MTCO' ) )
      IF( IPMTCO .NE. 0 .OR. ICALL .GT. 1 ) GO TO 500
         WRITE(6,9100)
 9100    FORMAT(//' +++++ WARNING FROM RDMTCO ++++++',/
     *            '   NO M T C O BANK IS FOUND !',/
     *            '    PROGRAMMED STOP FOLLOWS')
         STOP
  500 CONTINUE
C
C               COPY DRIFT CHAMBER INFORMATION IN MJET TO /CJDRCH/
C               ALSO SAVE THIS INFORMATION IN ARRAY SDRCH
C
      IPMJET = IDATA( IBLN( 'MJET' ) )
      LJET = IDATA(IPMJET)
      CALL MVCL( DRCH, 0, ADATA, IPMJET*4, LJET*4 )
      CALL MVCL( SDRCH, 0, DRCH, 0, LJET*4 )
C
C               COPY GENERAL GEOMETRY DATA FROM MGEO INTO /CGEO1/
C
      IPMGEO = IDATA( IBLN( 'MGEO' ) )
      LGEO = IDATA(IPMGEO)
      CALL MVCL( IGEO, 0, IDATA, IPMGEO*4, LGEO*4 )
C
C               FIX-UP THE VALUE OF ROTNK IF OLD DEFINITION
C
      IF( ROTNK .EQ. 847.0 ) ROTNK = 835.0
C

C
C               COPY VERTEX CHAMBER INFORMATION IN MVCC TO /CJVTXC/
C                   (IF MONTE CARLO DATA WITH VERTEX CHAMBER TRACKING)
      LVTXC = .FALSE.
      IPMVCC = IDATA( IBLN( 'MVCC' ) )
      IF( IPMVCC .LE. 0 ) GO TO 1000
         LVTXC = .TRUE.
         LVCC = IDATA(IPMVCC)
         CALL MVCL( VXCC, 0, ADATA, IPMVCC*4, LVCC*4 )
C
C               COPY GENERAL VERTEX CHAMBER GEOMETRY INFORMATION IN
C               BANK MGEV TO /CGEOV/
C
         IPMGEV = IDATA( IBLN( 'MGEV' ) )
         LGEV = IDATA(IPMGEV)
         CALL MVCL( GEOV, 0, ADATA, IPMGEV*4, LGEV*4 )
C
1000  CONTINUE
C
C    AT FIRST CALL, SAVE CONTENT OF /CBIN/ IN ARRAY SBIN
C                   SAVE CONTENT OF /CBINV/ IN ARRAY SBINV
C
      IF( ICALL .GT. 1 ) GO TO 1001
         CALL MVCL( SBIN, 0, ABIN, 0, LBIN*4 )
         CALL MVCL( SBINV, 0, ABINV, 0, LBINV*4 )
C
1001  CONTINUE
C                     CHECK MODE FLAG
C                                      IFLAG1: SMEARING FLAG
C                                             0:  UNSMEARED
C                                             1:    SMEARED
      IFLAG1 = IDATA(IPMTCO+1)
      IFLAG2 = IDATA(IPMTCO+2)
      IF( IFLAG1 .EQ. 1 ) GO TO 2000
C
C                                         **************************
C                                         *     UNSMEARED DATA     *
C                                         **************************
C
C
C       HOPT = HOPT1   MEANS DEFAULT SMEARING. HISTORICAL !!
C
CCC   IF( HOPT .EQ. HOPT1 ) CALL MVCL( ABIN, 0, SBIN, 0, LBIN*4 )
      CALL MVCL( ABIN, 0, SBIN, 0, LBIN*4 )
      CALL MVCL( ABINV, 0, SBINV, 0, LBINV*4 )
C
C     HERE BINDL8 WILL HOLD REALISTIC TIME BIN VALUES, NORMALLY 0.380
C     BINMC HOLDS THE TIMING BINS COMING WITH THE UNSMEARED DATA: 0.005
C
      DO 1010 I=1,6
         BINDL8(I)  = TIME(I)
         BINMC(I)   = DRCH(19+I)
 1010 CONTINUE
C
C INITIALIZE IFLADB AND NFLAGS(3), TO ENABLE RDTRIG AND CODE AFTERWARDS
C THIS IS NECESSARY IF A SECOND FILE WITH CONSTANTS BANKS IS READ
C
      IFLADB = 0
      NFLAGS(3) = -1
C
C  ARRAY IDOUB IS A HELP ARRAY, TO KEEP DOUBLE HIT RESOLUTION IN UNITS
C  OF DRIFT TIME BINS
C   OBS!! ALL SMEARED DATA ARE KEPT IN UNITS OF FINE ORIGINAL RESOLUTION
C         THEREFORE BINMC IS USED AS UNIT. THE SAME IS TRUE IN RDRESO.
C
      DO 1020 I=1,3
         IDOUBL(I) = IFIX(DOUB(I) / BINMC(2*I-1))
 1020 CONTINUE
      DRCH(27) = ZOF
      DRCH(28) = ZRS
      DRCH(30) = ZL
      DRCH(31) = ZSC
C                              FILL CELL DEPENDENT DRIFT VELOCITY ARRAY
      DO 121 IR = 1,3
         ICLL = IR*24 - 23
         ICLH = IR*24
         IF( IR .EQ. 3 ) ICLH = 96
         DO 120 I = ICLL,ICLH
            DRIVEL(I,1) = BINMC(2*IR-1)
            DRIVEL(I,2) = BINMC(2*IR)
  120       CONTINUE
  121    CONTINUE
C
      GO TO 3000
C
C                                         **************************
C                                         *  ALREADY SMEARED DATA  *
C                                         **************************
C
C      OVERWRITE /CBIN/ WITH THE VALUES IN /CJDRCH/. THESE HAVE JUST
C      JUST BEEN COPIED FROM BANK MJET. THEN SAVE THESE VALUES IN SBIN
C
 2000 CONTINUE
      DO 2010 I=1,6
         TIME(I) = DRCH(I+19)
 2010 CONTINUE
      ZOF = DRCH(27)
      ZRS = DRCH(28)
      ZL  = DRCH(30)
      ZSC = DRCH(31)
C
C  SET ARRAY DRIVEL IN /CJDRCH/,FROM THE GLOBAL VALUES
C
      DO 141 IR = 1, 3
         TIM = DRCH(IR*2+18)
         ICLL = IR*24 - 23
         ICLH = IR*24
         IF( IR .EQ. 3 ) ICLH = 96
         DO 140 I = ICLL, ICLH
            DRIVEL(I,1) = TIM
            DRIVEL(I,2) = TIM
  140    CONTINUE
  141 CONTINUE
C
C NOW CHECK IF DOUBLE HIT RESO, RANDOM HITS ETC. ARE KEPT IN MTCO
C
      DO 2020 I=1,3
         DOUB(I) = -5.
         EPSI(I) = -1.
         IRN(I)  = -100
         IF( IFLAG2 .NE. 0) DOUB(I) = ADATA(IPMTCO+133+I)
         IF( IFLAG2 .NE. 0) EPSI(I) = ADATA(IPMTCO+136+I)
         IF( IFLAG2 .NE. 0) IRN(I)  = IDATA(IPMTCO+139+I)
         IDOUBL(I) = DOUB(I) / DRCH(2*I+18)
 2020 CONTINUE
C
C    CHECK IF MONTE - CARLO - DATA ARE SMEARED WITH NEW SUBROUTINE
C    RDRESO, THEN IDATA(IPMTCO+3) EQUAL 1
C
      IFLAG3 = IDATA(IPMTCO+3)
      ISMEAR = IFLAG3
C
      DO 600 I = 1,6
         BINDL8(I)   = DRCH(I+19)
         BINMC(I)   = DRCH(I+19)
         IF( IFLAG3 .EQ. 1 ) BINDL8(I) = ADATA(IPMTCO+3+I)
  600 CONTINUE
      RJITT = -1.
      DLRSLN(1) = -1.
      DLRSLN(2) = -1.
      DLRSLN(3) = -1.
      DLZSLN(1) = -1.
      DLZSLN(2) = -1.
      DLZSLN(3) = -1.
      IF( IFLAG3 .NE. 1 ) GO TO 620
        RJITT = ADATA(IPMTCO+10)
        IF( IDATA(IPMTCO).GE.156) CALL UCOPY(ADATA(IPMTCO+151),DLRSLN,3)
        IF( IDATA(IPMTCO).GE.159) CALL UCOPY(ADATA(IPMTCO+157),DLZSLN,3)
  620 CONTINUE
C
C                   GET THE SMEARING PARAMETERS FOR VERTEX CHAMBER
C                   FROM BANK MTCO
C
      IF( .NOT. LVTXC )  GO TO 2026
        SMPRMV(1) = -1.
        SMPRMV(2) = -1.
        SMPRMV(3) = -1.
        DTRSVV    = ADATA(IPMTCO + 143)
        ZRSVV     = ADATA(IPMTCO + 144)
        EFFVV(1)  = ADATA(IPMTCO + 145)
        EFFVV(2)  = ADATA(IPMTCO + 146)
        DOUBVV(1) = ADATA(IPMTCO + 147)
        DOUBVV(2) = ADATA(IPMTCO + 148)
        DOUBVV(3) = ADATA(IPMTCO + 149)
        IRNHVV    = IDATA(IPMTCO + 150)
        IF( IDATA(IPMTCO).GE.156) CALL UCOPY(ADATA(IPMTCO+154),SMPRMV,3)
C
 2026 CONTINUE
C                            NOW COPY NOT ALLOWED, CONTENTS OF SBIN (THE
C                            ORIGINAL CONTENTS OF CBIN) WILL BE
C                            OVERWRITTEN
CCC   CALL MVCL( SBIN, 0, ABIN, 0, LBIN*4 )
C
C   GET THE DETECTOR STATUS AT THE TIME OF SMEARING
C     THIS INFORMATION IS ONLY AVAILABLE IF IFLAG2.NE.0
C
      IF( IFLAG2 .EQ. 0 )  GO TO 2040
         CALL MVCL( TSTAT1, 0, IDATA, (IPMTCO+10)*4, 110*4 )
         CALL MVCL( TSTAT2, 0, IDATA, (IPMTCO+120)*4, 13*4 )
 2040 CONTINUE
C
C   EARLIER VERSIONS OF CTRIGG (CTR123) MAY HAVE BEEN STORED IN MTCO
C   THIS COULD HAVE HAPPENED IN EARLIER VERSIONS OF TP PROGRAM
C   IF SO, COPY THE INFORMATION INTO PRESENT /CTRIGG/
C
      CALL MVCL( TSTAT3, 0, IDATA, (IPMTCO+10)*4, 52*4 )
      CALL MVCL( TSTAT4, 0, IDATA, (IPMTCO+62)*4, 13*4 )
      CALL MVCL( TSTAT3, 52*4, IDATA, (IPMTCO+75)*4, 4*4 )
C
C  CHECK IF OLD IWCOLL IS SET IN ISTAT3(4)
C
      IF( ISTAT3(4) .NE. 3) GO TO 2050
C
      IFLAG2 = 2
      WRITE(6,2041)
2041  FORMAT(' *** THESE DATA HAVE OLD VERSION OF COMMON /CTR123/ AND /C
     $RDSTA/ STORED IN MTCO ****')
      WRITE(6,2042)
2042  FORMAT(' *** THE CONSTANTS ARE COPIED INTO CURRENT COMMONS. THE CO
     $RRESPONDING DATE IS GIVEN IN THE LATER HEAD BANKS ***')
C
      IHIST(1) = 0
      IHIST(2) = 0
      IHIST(3) = 0
      NBPTFW = ISTAT3(2)
      NTOFC  = ISTAT3(3)
      IWCOLL = ISTAT3(4)
      NTFCOL = ISTAT3(5)
      HLGTOT(1,1) = HSTAT3(22)
      HLGTOT(2,1) = HSTAT3(21)
      HLGTOT(3,1) = HSTAT3(20)
      HLGTOT(4,1) = HSTAT3(19)
      HLGTL = HSTAT3(23)
      HLGTH = HSTAT3(24)
      HITCLL(1) = HSTAT3(25)
      HITCLL(2) = HSTAT3(26)
      HITCLL(3) = HSTAT3(27)
      HITWLL(1) = HSTAT3(28)
      HITWLL(2) = HSTAT3(29)
      HITWLL(3) = HSTAT3(30)
      HITSUM(1) = HSTAT3(31)
      HITSUM(2) = HSTAT3(32)
      HITSUM(3) = HSTAT3(33)
      HCHAMB(1) = HSTAT3(34)
      HCHAMB(2) = HSTAT3(35)
      HCHAMB(3) = HSTAT3(36)
      DO 2044  I = 1,16
         HMASK(I,1) = HSTAT3(36+I)
         HMASK(I,2) = HSTAT3(52+I)
         HMASK(I,3) = HSTAT3(68+I)
2044  CONTINUE
      DO 2045  I = 1,10
         HDEADC(I) = HSTAT3(84+I)
2045  CONTINUE
      HACC1  = HSTAT3(96)
      HACC2  = HSTAT3(97)
      HACC3  = HSTAT3(98)
      HACCM  = HSTAT3(99)
      HFMPRL = HSTAT3(100)
      HFMPRH = HSTAT3(101)
      HMPRON = HSTAT3(102)
      IWMPRG = ISTAT3(52)
      HACC4  = HSTAT3(105)
      HWCOLN = HSTAT3(106)
      NTFCLN = HSTAT3(108) + 1
      IWCOLN = ISTAT3(55)
      IWIDT2 = ISTAT3(56)
C
      NDEAD  = ISTAT4(1)
      NCDEAD = ISTAT4(2)
      DO 2048  I = 1,10
         HITD(I)   = HSTAT4(4+I)
         HCELLD(I) = HSTAT4(14+I)
2048  CONTINUE
      IPHALG = ISTAT4(13)
C
2050  CONTINUE
C                             FOR ALREADY SMEARED DATA, PRINT STATUS
C                      COMPARE CURRENT STATUS TO BACKUP
C                      IN ORDER TO AVOID UNNECESSARY PRINT
      IF(NFLAGS(8).NE.0) CALL PRAGAI(IPRIT)
      NFLAGS(8) = 0
      IF(IPRIT.NE.0) NFLAGS(9) = 1
      IF(NFLAGS(9).NE.0)  WRITE(6,8010)
8010  FORMAT('  RDMTCO: FLAG9 SET TO WRITE CONSTANTS RECORDS ON OUTPUT')
      IF(IPRIT.NE.0) CALL PRSTAT(IFLAG1,IFLAG2,IFLAG3)
C
C                                         **************************
C                                         *  ENTER HERE FOR BOTH   *
C                                         * SMEARED AND UNSMEARED  *
C                                         *    MONTE CARLO DATA    *
C                                         **************************
C
3000  CONTINUE
      DRIDEV = DRCH( 32 )
      DRISIN = SIN( DRIDEV )
      DRICOS = COS( DRIDEV )
C
C  SET CELL DEPENDENT CONSTANTS IN /CJDRCH/ FROM THE GLOBAL VALUES
C
      DO 111 J=1,2
         DO 110 I=1,96
            DRIROT(I,J) = DRIDEV
            SINDRI(I,J) = DRISIN
            COSDRI(I,J) = DRICOS
  110    CONTINUE
  111 CONTINUE
C
C                   SET CELL DEPENDENT CONSTANTS FOR THE VERTEX CHAMBER
C                   IN /CJVTXC/ FROM THE GLOBAL VALUES
C
      IF( .NOT. LVTXC )  GO TO 150
         DO 145  I = 1, 24
            DRILOR(I) = VXCC(7)
            CSLORA(I) = VXCC(8)
            SNLORA(I) = VXCC(9)
            DRVELO(I) = VXCC(15)
  145    CONTINUE
C
C THE FOLLOWING FUDGE IS INTRODUCED TO KEEP COMPATIBILITY WITH
C THE OLD TP PROGRAMS. IN THOSE PROGRAMS THE MTCO EVENT WILL BE WRITTEN
C OUT IMMEDIATELY, BEFORE READING THE MUCO EVENT. NOTE THAT THIS IMPLIES
C A LOGICAL ERROR, SINCE /CTR123/ OR /CTRIGG/ IS NOT UPDATED BEFORE
C THE FIRST EVENT HAS BEEN READ AND RDDATE BEEN CALLED (IN RDJETC).
C
  150 CALL BDLS( 'MTCO', 1)
      CALL BCRE( IPMTCO, 'MTCO', 1, 159, &9090, IER )
C
C       COPY DETECTOR STATUS INTO MTCO BANK
C
      CALL MVCL( IDATA, (IPMTCO+10)*4, TSTAT1, 0, 110*4 )
      CALL MVCL( IDATA, (IPMTCO+120)*4, TSTAT2, 0, 13*4 )
C
C COPY DOUB, EPSI AND IRN INTO MTCO
C
      DO 1011 I=1,3
         ADATA(IPMTCO+133+I) = DOUB(I)
         ADATA(IPMTCO+136+I) = EPSI(I)
         IDATA(IPMTCO+139+I) = IRN(I)
1011  CONTINUE
      IF( .NOT. LVTXC )  GO TO 1012
         ADATA(IPMTCO + 143) = DTRSVV
         ADATA(IPMTCO + 144) = ZRSVV
         ADATA(IPMTCO + 145) = EFFVV(1)
         ADATA(IPMTCO + 146) = EFFVV(2)
         ADATA(IPMTCO + 147) = DOUBVV(1)
         ADATA(IPMTCO + 148) = DOUBVV(2)
         ADATA(IPMTCO + 149) = DOUBVV(3)
         IDATA(IPMTCO + 150) = IRNHVV
         ADATA(IPMTCO+154) = SMPRMV(1)
         ADATA(IPMTCO+155) = SMPRMV(2)
         ADATA(IPMTCO+156) = SMPRMV(3)
C
C  WORD2 :   DETECTOR STATUS AND SOME CBIN VARIABLES ARE STORED
 1012 IDATA(IPMTCO+2) = 1
C
C  WORD3 :   BINDL8 AND RJITT SMEARING VARIABLES ARE STORED, IF ISMEAR=100005670
C
      IDATA(IPMTCO+3) = ISMEAR
      IF( ISMEAR .EQ. 0) GO TO 1111
C
C             COPY BINDL8 AND RJITT INTO MTCO
C
         DO 1013 I=1,6
            ADATA(IPMTCO+3+I) = BINDL8(I)
1013     CONTINUE
         ADATA(IPMTCO+10) = RJITT
         ADATA(IPMTCO+151) = DLRSLN(1)
         ADATA(IPMTCO+152) = DLRSLN(2)
         ADATA(IPMTCO+153) = DLRSLN(3)
         ADATA(IPMTCO+157) = DLZSLN(1)
         ADATA(IPMTCO+158) = DLZSLN(2)
         ADATA(IPMTCO+159) = DLZSLN(3)
1111  CONTINUE
C
C  WORD1 :   THIS IS SMEARED MONTE CARLO DATA
C     IDATA(IPMTCO+1) = 1
C          THIS FLAG IS SET BY THE CALLING PROGRAM, I.E. TPMAIN
C
C
C FOR USERS WHICH HAVE NOT INITIALIZED /CADMIN/, PRINT A WARNING
C
      IF( IEVTP .EQ. 1 .OR. IEVTP .EQ. 2) GO TO 9090
      WRITE(6,9089)
9089  FORMAT(' '/)
      WRITE(6,9091)
9091  FORMAT(' ',30('*'))
      WRITE(6,9092)
9092  FORMAT(' *****     WARNING    ********')
      WRITE(6,9091)
      WRITE(6,9093)
9093  FORMAT(' RDMTCO HAS COPIED TRIGGER AND DETECTOR STATUS INFORMATION
     $ INTO BANK MTCO.')
      WRITE(6,9094)
9094  FORMAT(' THIS VERSION OF THE TP PROGRAM WILL WRITE IT OUT ON THE O
     $UTPUT FILE IMMEDIATELY,')
      WRITE(6,9095)
9095  FORMAT(' BUT THE PROPER VERSION OF THE STATUS HAS NOT YET BEEN SET
     $, SINCE THE FIRST EVENT HAS NOT BEEN READ YET.')
      WRITE(6,9096)
9096  FORMAT(' BE AWARE THAT ERRORS MAY BE PRODUCED WITH THIS ILLOGICAL
     $PROCEDURE !!!')
      WRITE(6,9091)
      WRITE(6,9089)
C
9090  CONTINUE
      RETURN
C-----------------------------------------------------------------------
      ENTRY RDJETC
C-----------------------------------------------------------------------
C
C      SMEAR JETC BANK DATA, PUT IN INEFFICIENCIES, RANDOM HITS1
C      AND FINITE DOUBLE PULSE RESOLUTION.
C      PARAMETERS FOR SMEARING ARE IETHER DEFAULT OR HAVE BEEN SET BY A
C      PREVIOUS CALL TO RDMTCO.
C      PARAMETERS FOR TRIGGER AND INNER DETECTOR STATUS ARE SET BY THE
C      CALL TO RDTRIG
C-----------------------------------------------------------------------
C  FIRST SAVE HEAD DATE (WORDS 6-8) INTO HEAD WORDS 96-98.
C    THE EVENT DATE WILL BE OVERWRITTEN BY RDDATE, FOR TRIGGER VERSION
C-
       CALL RDHEAD
C-  NOW SET COMMONS /CTRIGG/ AND /CRDSTA/, AS WELL AS /CBIN/
       CALL RDTRIG
C                      COMPARE CURRENT STATUS TO BACKUP
C                      IN ORDER TO AVOID UNNECESSARY PRINT
      IPRIT = 0
      IF(NFLAGS(8).NE.0) CALL PRAGAI(IPRIT)
      NFLAGS(8) = 0
      IF(IPRIT.NE.0) NFLAGS(9) = 1
C     IF(NFLAGS(9).NE.0)  WRITE(6,8011)
C011  FORMAT('  RDJETC: FLAG SET TO WRITE CONSTANTS RECORDS ON OUTPUT')
      IF(IPRIT.NE.0) CALL PRSTAT(IFLAG1,IFLAG2,IFLAG3)
C
C  SINCE SOME OF THE INNER DETECTOR VARIABLES IN /CBIN/ ARE UPDATED
C  IN RDTRIG, REPEAT SOME OF THE RDMTCO ACTIONS HERE
C
C
C  ARRAY IDOUB IS A HELP ARRAY, TO KEEP DOUBLE HIT RESOLUTION IN UNITS
C  OF DRIFT TIME BINS
C   OBS!! ALL SMEARED DATA ARE KEPT IN UNITS OF FINE ORIGINAL RESOLUTION
C         THEREFORE BINMC IS USED AS UNIT. THE SAME IS TRUE IN RDRESO.
C
      IF(IFLADB.NE.0) GO TO 7021
      DO 7020 I=1,3
         IDOUBL(I) = IFIX(DOUB(I) / BINMC(2*I-1))
 7020 CONTINUE
C
      IFLADB = 1
7021  CONTINUE
C
C                                          VERTEX CHAMBER
C
      IF( .NOT. LVTXC )  GO TO 5304
C
         CALL RDRESV
C
         IPVTXC = IDATA (IBLN('VTXC'))
         IF( IPVTXC .LE. 0 )
     *      CALL BCRE ( IPVTXC, 'VTXC',10, 5, &5304, IEVT )
         CALL BSAW(1, 'VTXC')
         IDATA(IPVTXC + 1 ) = 5
C                                          DOUB. HIT RESO., INEFF.,
C                                          RANDOM HITS
         CALL RDMODV( IRNHVV, EFFVV, DOUBVV )
 5304 CONTINUE
C
C
C                       COPY UNSMEARED 'JETC' BANK 8 TO BANK 9
C
      IPJ = IDATA( IBLN( 'JETC' ) )
      IF( IPJ .LE. 0 ) GO TO 401
         IF( IJETCI .EQ. 0) GO TO 401
C
            LENGTH = IDATA(IPJ)
            CALL BCRE( IPJ9, 'JETC', 9, LENGTH, &401, IER )
            CALL MVCL( IDATA, IPJ9*4, IDATA, IPJ*4, LENGTH*4 )
C
C                       NOW SMEAR TIME AND Z-COORD VALUES
C
 401  CALL RDRESO( BINMC )
C
      IF( IPJ .LE. 0 ) CALL BCRE( IPJ, 'JETC', 8, 50, &7788, IE )
      CALL BSAW( 1, 'JETC' )
C
C                       CONSIDER DOUBLE HIT RESOLUTION,
C                       INEFFICIENCIES AND RANDOM HITS
C
      CALL RDMODN( IRN, EPSI, IDOUBL )
C
C                       SET CORRECT STANDARD DEVIATIONS IN PATR BANK
C
      CALL RDPATR
C                       CREATE TRIGGER BANKS
7788  CALL RDTRG1
      CALL RDTRG2
C                       DELETE LG-BLOCKS BELOW READOUT THRESHOLD IPHALG
      CALL RDALGN
      RETURN
      END
