      PROGRAM GEOCHECK
C----------------------------------------------------------------------
C-
C-   Purpose and Methods : 
C-
C-   Inputs  : 
C-   Outputs : 
C-   Controls: 
C-
C-   Created  31-OCT-1990   MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE
C-
C----------------------------------------------------------------------
      IMPLICIT NONE
      INCLUDE 'L1TEM:LEVEL1_LOOKUP.PARAMS'
      REAL         NEW_TOWER_RZ_COORD( POS_ETA:NEG_ETA, 
     &                                ETA_MIN:ETA_MAX,
     &                                PHI_MIN:PHI_MAX,
     &                                EM_TOWER:TOT_TOWER,
     &                                R_COORD:Z_COORD )
      REAL         OLD_TOWER_RZ_COORD( POS_ETA:NEG_ETA, 
     &                                ETA_MIN:ETA_MAX,
     &                                PHI_MIN:PHI_MAX,
     &                                EM_TOWER:TOT_TOWER,
     &                                R_COORD:Z_COORD )
C
      INTEGER SIGN_ETA, ETA, ETA2, PHI, CHANNEL, RZ
      REAL SIN_NEW, SIN_OLD
      REAL R, Z
      LOGICAL OK
      CHARACTER*80 LINE
      REAL SIN_THETA
      REAL ERR_HOLD(1:20)
C
      SIN_THETA(R,Z) = R / (SQRT(R**2 + Z**2))
C
      CALL D0OPEN(12, 'TRIGGER_GEOMETRY.TXT', 'IF', OK)
      IF (.NOT. OK) GOTO 999
      CALL D0OPEN(13, 'OLD_TRIGGER_GEOMETRY.TXT', 'IF', OK)
      IF (.NOT. OK) GOTO 999
C
  100 FORMAT( A )
  200 FORMAT( 5F14.0)
      READ(12,100) LINE
      READ(12,100) LINE
      READ(12,100) LINE
      READ(12,100) LINE
      READ(12,100) LINE
C
      DO PHI = 1, 32
        READ(12,100) LINE
        DO ETA = 20, 1, -5
          READ(12, 200) (NEW_TOWER_RZ_COORD(NEG_ETA, ETA - ETA2, PHI,
     &      EM_TOWER, R_COORD), ETA2 = 0, 4 )
        END DO
        DO ETA = 1, 20, 5
          READ(12, 200) (NEW_TOWER_RZ_COORD(POS_ETA, ETA + ETA2, PHI,
     &      EM_TOWER, R_COORD), ETA2 = 0, 4)
        END DO
      END DO
C
      READ(12,100) LINE
      READ(12,100) LINE
      READ(12,100) LINE
      DO PHI = 1, 32
        READ(12,100) LINE
        DO ETA = 20, 1, -5
          READ(12, 200) (NEW_TOWER_RZ_COORD(NEG_ETA, ETA - ETA2, PHI,
     &      HD_TOWER, R_COORD), ETA2 = 0, 4 )
        END DO
        DO ETA = 1, 20, 5
          READ(12, 200) (NEW_TOWER_RZ_COORD(POS_ETA, ETA + ETA2, PHI,
     &      HD_TOWER, R_COORD), ETA2 = 0, 4)
        END DO
      END DO
C
      READ(12,100) LINE
      READ(12,100) LINE
      READ(12,100) LINE
      DO PHI = 1, 32
        READ(12,100) LINE
        DO ETA = 20, 1, -5
          READ(12, 200) (NEW_TOWER_RZ_COORD(NEG_ETA, ETA - ETA2, PHI,
     &      EM_TOWER, Z_COORD), ETA2 =  0, 4 )
        END DO
        DO ETA = 1, 20, 5
          READ(12, 200) (NEW_TOWER_RZ_COORD(POS_ETA, ETA + ETA2, PHI,
     &      EM_TOWER, Z_COORD), ETA2 = 0, 4)
        END DO
      END DO
C
      READ(12,100) LINE
      READ(12,100) LINE
      READ(12,100) LINE
      DO PHI = 1, 32
        READ(12,100) LINE
        DO ETA = 20, 1, -5
          READ(12, 200) (NEW_TOWER_RZ_COORD(NEG_ETA, ETA - ETA2, PHI,
     &      HD_TOWER, Z_COORD), ETA2 =  0, 4 )
        END DO
        DO ETA = 1, 20, 5
          READ(12, 200) (NEW_TOWER_RZ_COORD(POS_ETA, ETA + ETA2, PHI,
     &      HD_TOWER, Z_COORD), ETA2 = 0, 4)
        END DO
      END DO
C
C Old geometry now
C
      READ(13,100) LINE
      READ(13,100) LINE
      READ(13,100) LINE
      READ(13,100) LINE
      READ(13,100) LINE
C
      DO PHI = 1, 32
        READ(13,100) LINE
        DO ETA = 20, 1, -5
          READ(13, 200) (OLD_TOWER_RZ_COORD(NEG_ETA, ETA - ETA2, PHI,
     &      EM_TOWER, R_COORD), ETA2 =  0, 4)
        END DO
        DO ETA = 1, 20, 5
          READ(13, 200) (OLD_TOWER_RZ_COORD(POS_ETA, ETA + ETA2, PHI,
     &      EM_TOWER, R_COORD), ETA2 = 0, 4)
        END DO
      END DO
C
      READ(13,100) LINE
      READ(13,100) LINE
      READ(13,100) LINE
      DO PHI = 1, 32
        READ(13,100) LINE
        DO ETA = 20, 1, -5
          READ(13, 200) (OLD_TOWER_RZ_COORD(NEG_ETA, ETA - ETA2, PHI,
     &      HD_TOWER, R_COORD), ETA2 = 0, 4 )
        END DO
        DO ETA = 1, 20, 5
          READ(13, 200) (OLD_TOWER_RZ_COORD(POS_ETA, ETA + ETA2, PHI,
     &      HD_TOWER, R_COORD), ETA2 = 0, 4)
        END DO
      END DO
C
      READ(13,100) LINE
      READ(13,100) LINE
      READ(13,100) LINE
      DO PHI = 1, 32
        READ(13,100) LINE
        DO ETA = 20, 1, -5
          READ(13, 200) (OLD_TOWER_RZ_COORD(NEG_ETA, ETA - ETA2, PHI,
     &      EM_TOWER, Z_COORD), ETA2 =  0, 4 )
        END DO
        DO ETA = 1, 20, 5
          READ(13, 200) (OLD_TOWER_RZ_COORD(POS_ETA, ETA + ETA2, PHI,
     &      EM_TOWER, Z_COORD), ETA2 = 0, 4)
        END DO
      END DO
C
      READ(13,100) LINE
      READ(13,100) LINE
      READ(13,100) LINE
      DO PHI = 1, 32
        READ(13,100) LINE
        DO ETA = 20, 1, -5
          READ(13, 200) (OLD_TOWER_RZ_COORD(NEG_ETA, ETA - ETA2, PHI,
     &      HD_TOWER, Z_COORD), ETA2 = 0, 4 )
        END DO
        DO ETA = 1, 20, 5
          READ(13, 200) (OLD_TOWER_RZ_COORD(POS_ETA, ETA + ETA2, PHI,
     &      HD_TOWER, Z_COORD), ETA2 = 0, 4)
        END DO
      END DO
C
C
C
C  300 FORMAT(' ', A3, ' ', I2,  ' ', 20F12.4 )
      DO PHI = 1, 32
        DO ETA = 19, 1, -1
          SIN_NEW = SIN_THETA(NEW_TOWER_RZ_COORD(NEG_ETA, ETA, PHI,
     &      EM_TOWER, R_COORD), NEW_TOWER_RZ_COORD(NEG_ETA, ETA, PHI,
     &      EM_TOWER, Z_COORD))
          SIN_OLD = SIN_THETA(OLD_TOWER_RZ_COORD(NEG_ETA, ETA, PHI,
     &      EM_TOWER, R_COORD), OLD_TOWER_RZ_COORD(NEG_ETA, ETA, PHI,
     &      EM_TOWER, Z_COORD))
          ERR_HOLD(ETA) = 100 * (SIN_NEW - SIN_OLD) / SIN_OLD
        END DO
        WRITE(6, *) 'EM', PHI, ' NEG_ETA'
        WRITE(6, *) (ERR_HOLD(ETA), ETA = 19, 1, -1) 
        DO ETA = 1, 19
          SIN_NEW = SIN_THETA(NEW_TOWER_RZ_COORD(POS_ETA, ETA, PHI,
     &      EM_TOWER, R_COORD), NEW_TOWER_RZ_COORD(POS_ETA, ETA, PHI,
     &      EM_TOWER, Z_COORD))
          SIN_OLD = SIN_THETA(OLD_TOWER_RZ_COORD(POS_ETA, ETA, PHI,
     &      EM_TOWER, R_COORD), OLD_TOWER_RZ_COORD(POS_ETA, ETA, PHI,
     &      EM_TOWER, Z_COORD))
          ERR_HOLD(ETA) = 100 * (SIN_NEW - SIN_OLD) / SIN_OLD
        END DO
        WRITE(6, *) 'EM', PHI, ' POS_ETA'
        WRITE(6, *) (ERR_HOLD(ETA), ETA = 1, 19 ) 
      END DO
C
      DO PHI = 1, 32
        DO ETA = 20, 1, -1
          SIN_NEW = SIN_THETA(NEW_TOWER_RZ_COORD(NEG_ETA, ETA, PHI,
     &      HD_TOWER, R_COORD), NEW_TOWER_RZ_COORD(NEG_ETA, ETA, PHI,
     &      HD_TOWER, Z_COORD))
          SIN_OLD = SIN_THETA(OLD_TOWER_RZ_COORD(NEG_ETA, ETA, PHI,
     &      HD_TOWER, R_COORD), OLD_TOWER_RZ_COORD(NEG_ETA, ETA, PHI,
     &      HD_TOWER, Z_COORD))
          ERR_HOLD(ETA) = 100 * (SIN_NEW - SIN_OLD) / SIN_OLD
        END DO
        WRITE(6, *) 'HD', PHI, ' NEG_ETA'
        WRITE(6, *) (ERR_HOLD(ETA), ETA = 20, 1, -1) 
        DO ETA = 1, 20
          SIN_NEW = SIN_THETA(NEW_TOWER_RZ_COORD(POS_ETA, ETA, PHI,
     &      HD_TOWER, R_COORD), NEW_TOWER_RZ_COORD(POS_ETA, ETA, PHI,
     &      HD_TOWER, Z_COORD))
          SIN_OLD = SIN_THETA(OLD_TOWER_RZ_COORD(POS_ETA, ETA, PHI,
     &      HD_TOWER, R_COORD), OLD_TOWER_RZ_COORD(POS_ETA, ETA, PHI,
     &      HD_TOWER, Z_COORD))
          ERR_HOLD(ETA) = 100 * (SIN_NEW - SIN_OLD) / SIN_OLD
        END DO
        WRITE(6, *) 'HD', PHI, ' POS_ETA'
        WRITE(6, *) (ERR_HOLD(ETA), ETA = 1, 20 ) 
      END DO
              

C----------------------------------------------------------------------
  999 CONTINUE
      END
