      SUBROUTINE SIMU_LSM()
C----------------------------------------------------------------------
C-
C-   Purpose and Methods : Dispatch routine for SIMU_LSM
C-
C-   Inputs :  None
C-   Outputs : None
C-
C-   Created   20-AUG-90   by MENU_MAKER
C-   Updated   4-SEP-1990  MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE
C-
C----------------------------------------------------------------------
      IMPLICIT NONE
      INCLUDE 'LSMP$SOURCE:PARSE_TOKENS.PARAMS'
      INCLUDE 'LSMP$SOURCE:PARSE_TOKENS.INC'
      CHARACTER*40 COMAND
      LOGICAL GOTOP
      LOGICAL FIRST
      DATA FIRST/.TRUE./
C----------------------------------------------------------------------
C
C       Check if a file has been loaded
C
      IF ((LSM_FILE_LOADED .EQV. .FALSE.) .AND.
     &  (LSO_FILE_LOADED .EQV. .FALSE.)) THEN
        CALL OUTMSG('1Cannot proceed without a file loaded')
        CALL PFWAIT()
        GOTO 999
      ENDIF
C
      COMAND=' '
    1 CONTINUE
      IF (COMAND.NE.'EXIT'.AND..NOT.GOTOP()) THEN
        CALL MENUDO('Simulation Routines ','SIMU_LSM',
     &    COMAND)
        IF(COMAND.EQ.'SIM_LEV0') THEN
          CALL SIM_LEV0
        ELSEIF(COMAND.EQ.'SIM_ADC') THEN
          CALL SIM_ADC
        ELSEIF(COMAND.EQ.'PROM_RES') THEN
          CALL PROM_RES
        ELSEIF(COMAND.EQ.'SIM_TTRH') THEN
          CALL SIM_TTRH
        ELSEIF(COMAND.EQ.'SIM_GTRH') THEN
          CALL SIM_GTRH
        ELSEIF(COMAND.EQ.'SHO_TREE') THEN
          CALL SHO_TREE
        ELSEIF(COMAND.EQ.'SHO_ADCE') THEN
          CALL SHO_ADCE
        ELSEIF(COMAND.NE.'EXIT'.AND.COMAND.NE.'BLANK') THEN
          CALL OUTMSG('0No ACTION defined for that command'//CHAR(7))
        ENDIF
        GOTO 1
      ENDIF
  999 RETURN
      END
C
C
C
      SUBROUTINE SIM_LEV0
C----------------------------------------------------------------------
C-
C-   Purpose and Methods : Prompt for parameters, then call the simulation
C-   routine SIMUL_LEVEL0.
C-
C-   Inputs  : none
C-   Outputs : none
C-   Controls: none
C-
C-   Created   4-SEP-1990   MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE
C-
C----------------------------------------------------------------------
      IMPLICIT NONE
C----------------------------------------------------------------------
      REAL Z_VERTEX
      INTEGER L0_BIN
      LOGICAL L0_VALID
      CHARACTER*132 MESSAGE
C
      INTEGER  PFNUM
      EXTERNAL PFNUM
C
C
C
      CALL GETPAR(1, 'Position of interaction vertex (cm) > ', 'R',
     &  Z_VERTEX)
      IF (PFNUM() .NE. 0) GOTO 999
C
      CALL SIMUL_LEVEL0(Z_VERTEX, L0_BIN, L0_VALID)
C
C
      WRITE (MESSAGE, 100) L0_BIN
  100 FORMAT( ' Level 0 bin #', I3)
      CALL OUTMSG(MESSAGE)
      IF (L0_VALID) THEN
        CALL OUTMSG(' Vertex position valid.')
      ELSE
        CALL OUTMSG(' Vertex position not valid.')
      ENDIF
C
      CALL PFWAIT()
C
  999 RETURN
      END
C
C
C
      SUBROUTINE SIM_ADC()
C----------------------------------------------------------------------
C-
C-   Purpose and Methods : Get parameters and do the equivalent of what is in
C-   the routine ADC_CONVERSIONS. The library routine simulates the analog to
C-   digital conversions over the entire detector, while this routine simulates
C-   the conversions for one trigger tower.
C-
C-   Inputs  : none
C-   Outputs : none
C-   Controls: none
C-
C-   Created  11-SEP-1990   MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE
C-
C----------------------------------------------------------------------
      IMPLICIT NONE
C----------------------------------------------------------------------
C
C       Global Declarations
C
      INCLUDE 'D0$PARAMS:LEVEL1_LOOKUP.PARAMS'
      INCLUDE 'D0$INC:LEVEL1_LOOKUP.INC'
      INCLUDE 'LSMP$SOURCE:LEVEL1_LOOKUP_EXPANSION.INC'
      INTEGER  PFNUM
      EXTERNAL PFNUM
C
C       Local variables
C
      INTEGER ETA, SIGN_ETA, PHI, ADC_BYTE
      REAL EM_ENERGY, HD_ENERGY, TEMP_ENERGY
      LOGICAL REPEAT
      CHARACTER*80 MESSAGE
C
      REPEAT = .TRUE.
      DO WHILE (REPEAT)
        CALL GETPAR(1, 'ETA coordinate of tower > ', 'I', ETA)
        IF (PFNUM() .NE. 0) GOTO 999
        IF ((ETA .EQ. 0) .OR. (ABS(ETA) .GT. 24)) THEN
          CALL OUTMSG(' ETA value not in range.')
        ELSE
          REPEAT = .FALSE.
        ENDIF
      END DO
C
      IF (ETA .LT. 0) THEN
        SIGN_ETA = NEG_ETA
        ETA = ABS(ETA)
      ELSE
        SIGN_ETA = POS_ETA
      ENDIF
C
      REPEAT = .TRUE.
      DO WHILE (REPEAT)
        CALL GETPAR(1, 'PHI coordinate of tower > ', 'I', PHI)
        IF (PFNUM() .NE. 0) GOTO 999
        IF ((PHI .LT. 1) .OR. (PHI .GT. 32)) THEN
          CALL OUTMSG(' PHI value not in range.')
        ELSE
          REPEAT = .FALSE.
        ENDIF
      END DO
C
C
      CALL GETPAR(1, 'Energy in EM tower > ', 'R', EM_ENERGY)
      IF (PFNUM() .NE. 0) GOTO 999
C
      CALL GETPAR(1, 'Energy in HD tower > ', 'R', HD_ENERGY)
      IF (PFNUM() .NE. 0) GOTO 999
C
C       Perform calculations for EM tower
C
      IF ( DAC_BYTE (SIGN_ETA,ETA,PHI,EM_TOWER) .EQ. 0 ) THEN
        ADC_BYTE = 0
      ELSE
C
        TEMP_ENERGY =   EM_ENERGY
     &                * ADC_CNT_VS_RAW_E (SIGN_ETA,ETA,PHI,EM_TOWER)
     &                + ADC_ZERESP (SIGN_ETA,ETA,PHI,EM_TOWER)
C
        IF ( TEMP_ENERGY .LT. 0.5 ) THEN
          ADC_BYTE = 0
        ELSE IF ( TEMP_ENERGY .GE. 254.5 ) THEN
          ADC_BYTE = 255
        ELSE
          ADC_BYTE = NINT(TEMP_ENERGY)
        END IF
C
      END IF
C
      WRITE(MESSAGE, 100) ADC_BYTE
  100 FORMAT(' EM tower ADC byte: ', I3)
      CALL OUTMSG(MESSAGE)
C
C       Perform calculations for HD tower
C
      IF ( DAC_BYTE (SIGN_ETA,ETA,PHI,HD_TOWER) .EQ. 0 ) THEN
        ADC_BYTE = 0
      ELSE
C
        TEMP_ENERGY =   HD_ENERGY
     &                * ADC_CNT_VS_RAW_E (SIGN_ETA,ETA,PHI,HD_TOWER)
     &                + ADC_ZERESP (SIGN_ETA,ETA,PHI,HD_TOWER)
C
        IF ( TEMP_ENERGY .LT. 0.5 ) THEN
          ADC_BYTE = 0
        ELSE IF ( TEMP_ENERGY .GE. 254.5 ) THEN
          ADC_BYTE = 255
        ELSE
          ADC_BYTE = NINT(TEMP_ENERGY)
        END IF
C
      END IF
      WRITE (MESSAGE, 200) ADC_BYTE
  200 FORMAT(' HD tower ADC byte: ', I3)
      CALL OUTMSG(MESSAGE)
C
      CALL PFWAIT()
C
  999 RETURN
      END
C
C
C
      SUBROUTINE PROM_RES()
C----------------------------------------------------------------------
C-
C-   Purpose and Methods : Prompt for parameters and call PROM_RESPONSE
C-
C-   Inputs  : none
C-   Outputs : none
C-   Controls: none
C-
C-   Created   4-SEP-1990   MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE
C-
C----------------------------------------------------------------------
      IMPLICIT NONE
C----------------------------------------------------------------------
C
C       Global declarations
C
      INCLUDE 'D0$PARAMS:LEVEL1_LOOKUP.PARAMS'
      INTEGER PFNUM
      EXTERNAL PFNUM
      INTEGER  TRULEN
      EXTERNAL TRULEN
C
C       Local declarations
C
      INTEGER L0_BIN
      INTEGER SIGN_ETA
      INTEGER ETA
      INTEGER PHI
      INTEGER EM_BYTE
      INTEGER HD_BYTE
      INTEGER LUQ_BYTE(EM_ET_QUANT:PY_QUANT)
C
      INTEGER NUM_PARAMETERS
      PARAMETER (NUM_PARAMETERS = 5)
      CHARACTER*33 PROMPTS(1:NUM_PARAMETERS)
      CHARACTER*1 TYPES(1:NUM_PARAMETERS)
      LOGICAL ERROR
      CHARACTER*132 MESSAGE
C
      DATA PROMPTS/ 'Level 0 bin number > ', 'ETA index > ',
     &  'PHI index > ',
     &  'EM tower byte > ', 'HD tower byte > '/
      DATA TYPES/ 'I', 'I','I','I','I'/
C
      ERROR = .FALSE.
      CALL GETPAR(NUM_PARAMETERS, PROMPTS, TYPES, L0_BIN, ETA, PHI,
     &  EM_BYTE, HD_BYTE)
C
      IF (PFNUM() .NE. 0) GOTO 999
C
      IF (ETA .GT. 0) THEN
        SIGN_ETA = POS_ETA
      ELSEIF (ETA .LT. 0) THEN
        SIGN_ETA = NEG_ETA
        ETA = ABS(ETA)
      ENDIF
C
      IF ((L0_BIN .LT. L0_BIN_MIN) .OR. (L0_BIN .GT. L0_BIN_MAX)) THEN
        CALL OUTMSG(' Level 0 bin number out of range.')
        ERROR = .TRUE.
      ENDIF
C
      IF ((ETA .EQ. 0) .OR. (ETA .GT. ETA_RANGE_MAX)) THEN
        CALL OUTMSG(' ETA value out of range.')
        ERROR = .TRUE.
      ENDIF
C
      IF ((PHI .LT. PHI_MIN) .OR. (PHI .GT. PHI_MAX)) THEN
        CALL OUTMSG(' PHI value out of range.')
        ERROR = .TRUE.
      ENDIF
C
      IF ((EM_BYTE .LT. 0) .OR. (EM_BYTE .GT. 255)) THEN
        CALL OUTMSG(' EM byte out of range.')
        ERROR = .TRUE.
      ENDIF
C
      IF ((HD_BYTE .LT. 0) .OR. (HD_BYTE .GT. 255)) THEN
        CALL OUTMSG(' HD byte out of range')
        ERROR = .TRUE.
      ENDIF
C
      IF (ERROR) THEN
        CALL PFWAIT()
        GOTO 999
      ENDIF
C
      CALL PROM_RESPONSES(SIGN_ETA, ETA, PHI, L0_BIN, EM_BYTE,
     &  HD_BYTE, LUQ_BYTE)
C
      WRITE (MESSAGE, 100) LUQ_BYTE(EM_ET_QUANT)
  100 FORMAT( ' EM ET Quantity byte: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE (MESSAGE, 200) LUQ_BYTE(EM_L2_QUANT)
  200 FORMAT(' EM L2 Quantity byte: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE (MESSAGE, 300) LUQ_BYTE(HD_ET_QUANT)
  300 FORMAT( ' HD ET Quantity byte: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE (MESSAGE, 400) LUQ_BYTE(HD_L2_QUANT)
  400 FORMAT(' HD L2 Quantity byte: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE (MESSAGE, 500) LUQ_BYTE(PX_QUANT)
  500 FORMAT(' PX Quantity byte: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE (MESSAGE, 600) LUQ_BYTE(PY_QUANT)
  600 FORMAT(' PY Quantity byte: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      CALL PFWAIT()
C
  999 RETURN
      END
C
C
C
      SUBROUTINE SIM_TTRH()
C----------------------------------------------------------------------
C-
C-   Purpose and Methods : Prompt for parameters and call the routine
C-   TOWER_THRESHOLD_TRANSLATION().
C-
C-   Inputs  : none
C-   Outputs : none
C-   Controls: none
C-
C-   Created   4-SEP-1990   MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE
C-
C----------------------------------------------------------------------
      IMPLICIT NONE
C----------------------------------------------------------------------
C
C       Global declarations
C
      INCLUDE 'D0$PARAMS:LEVEL1_LOOKUP.PARAMS'
      INTEGER  PFNUM
      EXTERNAL PFNUM
      INTEGER  TRULEN
      EXTERNAL TRULEN
C
C       Local variables
C
      INTEGER SIGN_ETA
      INTEGER ETA
      INTEGER PHI
      INTEGER THRSH_TYPE
      REAL    DESIRED_THRSH
      INTEGER HARDWARE_THRSH
C
      INTEGER NUM_PARAMS
      PARAMETER (NUM_PARAMS = 3)
      CHARACTER*30 PROMPTS(1:NUM_PARAMS)
      CHARACTER*1 TYPES(1:NUM_PARAMS)
      LOGICAL ERROR
      CHARACTER*132 MESSAGE
C
      DATA PROMPTS/ 'ETA index > ', 'PHI index > ',
     &  'Desired Threshold Energy > ' /
      DATA TYPES/ 'I', 'I', 'R'/
C
      ERROR = .FALSE.
      CALL GETPAR(NUM_PARAMS, PROMPTS, TYPES, ETA, PHI, DESIRED_THRSH)
      IF (PFNUM() .NE. 0) GOTO 999
C
      IF (ETA .GT. 0) THEN
        SIGN_ETA = POS_ETA
      ELSEIF (ETA .LT. 0) THEN
        SIGN_ETA = NEG_ETA
        ETA = ABS(ETA)
      ENDIF
C
      IF ((ETA .LT. ETA_RANGE_MIN) .OR. (ETA .GT. ETA_RANGE_MAX)) THEN
        CALL OUTMSG(' ETA index out of range.')
        ERROR = .TRUE.
      ENDIF
C
      IF ((PHI .LT. PHI_MIN) .OR. (PHI .GT. PHI_MAX)) THEN
        CALL OUTMSG(' PHI index out of range.')
        ERROR = .TRUE.
      ENDIF
C
      IF (ERROR) THEN
        CALL PFWAIT()
        GOTO 999
      ENDIF
C
      CALL TOWER_THRESHOLD_TRANSLATION(SIGN_ETA, ETA, PHI,
     &  TT_EMET_THRTYP, DESIRED_THRSH, HARDWARE_THRSH)
C
      WRITE (MESSAGE, 100) HARDWARE_THRSH
  100 FORMAT(' EM ET Threshold: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      CALL TOWER_THRESHOLD_TRANSLATION(SIGN_ETA, ETA, PHI,
     &  TT_HDVETO_THRTYP, DESIRED_THRSH, HARDWARE_THRSH)
C
      WRITE (MESSAGE, 200) HARDWARE_THRSH
  200 FORMAT(' Hadronic Veto Threshold: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      CALL TOWER_THRESHOLD_TRANSLATION(SIGN_ETA, ETA, PHI,
     &  TT_TOTET_THRTYP, DESIRED_THRSH, HARDWARE_THRSH)
C
      WRITE (MESSAGE, 300) HARDWARE_THRSH
  300 FORMAT(' Total ET Threshold: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      CALL PFWAIT()
C
  999 RETURN
      END
C
C
C
      SUBROUTINE SIM_GTRH()
C----------------------------------------------------------------------
C-
C-   Purpose and Methods : Prompt for a desired threshold and then call the
C-   routine GLOBAL_THRESHOLD_TRANSLATION.
C-
C-   Inputs  : none
C-   Outputs : none
C-   Controls: none
C-
C-   Created   5-SEP-1990   MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE
C-
C----------------------------------------------------------------------
      IMPLICIT NONE
C----------------------------------------------------------------------
C
C       Global Declarations
C
      INCLUDE 'D0$PARAMS:LEVEL1_LOOKUP.PARAMS'
      INTEGER  TRULEN
      EXTERNAL TRULEN
      INTEGER  PFNUM
      EXTERNAL PFNUM
C
C       Local Variables
C
      REAL DESIRED_THRESHOLD
      INTEGER HARDWARE_THRESHOLD
      CHARACTER*132 MESSAGE
C
      CALL GETPAR(1, 'Desired Threshold Energy > ', 'R',
     &  DESIRED_THRESHOLD)
      IF (PFNUM() .NE. 0) GOTO 999
C
      CALL GLOBAL_THRESHOLD_TRANSLATION(GL_EMET_THRTYP,
     &  DESIRED_THRESHOLD, HARDWARE_THRESHOLD)
      WRITE(MESSAGE, 100) HARDWARE_THRESHOLD
  100 FORMAT(' EM ET Hardware Threshold: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      CALL GLOBAL_THRESHOLD_TRANSLATION(GL_EML2_THRTYP,
     &  DESIRED_THRESHOLD, HARDWARE_THRESHOLD)
      WRITE(MESSAGE, 200) HARDWARE_THRESHOLD
  200 FORMAT(' EM Second Lookup Hardware Threshold: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      CALL GLOBAL_THRESHOLD_TRANSLATION(GL_HDET_THRTYP,
     &  DESIRED_THRESHOLD, HARDWARE_THRESHOLD)
      WRITE(MESSAGE, 300) HARDWARE_THRESHOLD
  300 FORMAT(' HD ET Hardware Threshold: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      CALL GLOBAL_THRESHOLD_TRANSLATION(GL_HDL2_THRTYP,
     &  DESIRED_THRESHOLD, HARDWARE_THRESHOLD)
      WRITE(MESSAGE, 400) HARDWARE_THRESHOLD
  400 FORMAT(' HD Second Lookup Hardware Threshold: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      CALL GLOBAL_THRESHOLD_TRANSLATION(GL_TOTET_THRTYP,
     &  DESIRED_THRESHOLD, HARDWARE_THRESHOLD)
      WRITE(MESSAGE, 500) HARDWARE_THRESHOLD
  500 FORMAT(' Total ET Hardware Threshold: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      CALL GLOBAL_THRESHOLD_TRANSLATION(GL_TOTL2_THRTYP,
     &  DESIRED_THRESHOLD, HARDWARE_THRESHOLD)
      WRITE(MESSAGE, 600) HARDWARE_THRESHOLD
  600 FORMAT(' Total Second Lookup Hardware Threshold: ', I3)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      CALL PFWAIT()
C
  999 RETURN
      END
C
C
C
      SUBROUTINE SHO_TREE()
C----------------------------------------------------------------------
C-
C-   Purpose and Methods : Display the contents of the array TREE_OFFSET
C-
C-   Inputs  : none
C-   Outputs : none
C-   Controls: none
C-
C-   Created   5-SEP-1990   MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE
C-
C----------------------------------------------------------------------
      IMPLICIT NONE
C----------------------------------------------------------------------
C
C       Global Declarations
C
      INCLUDE 'D0$PARAMS:LEVEL1_LOOKUP.PARAMS'
      INCLUDE 'D0$INC:LEVEL1_LOOKUP.INC'
      INCLUDE 'LSMP$SOURCE:LEVEL1_LOOKUP_EXPANSION.INC'
      INTEGER  TRULEN
      EXTERNAL TRULEN
C
      CHARACTER*132 MESSAGE
C
      CALL OUTMSG(' TREE OFFSET VALUES')
      CALL OUTMSG(' ------------------')
C
      WRITE(MESSAGE, 100) TREE_OFFSET(EM_ET_QUANT)
  100 FORMAT(' EM ET Value: ', I)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE(MESSAGE, 200) TREE_OFFSET(EM_L2_QUANT)
  200 FORMAT(' EM L2 Value: ', I)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE(MESSAGE, 300) TREE_OFFSET(HD_ET_QUANT)
  300 FORMAT(' HD ET Value: ', I)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE(MESSAGE, 400) TREE_OFFSET(HD_L2_QUANT)
  400 FORMAT(' HD L2 Value: ', I)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE(MESSAGE, 500) TREE_OFFSET(PX_QUANT)
  500 FORMAT(' PX Value: ', I)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE(MESSAGE, 600) TREE_OFFSET(PY_QUANT)
  600 FORMAT(' PY Value: ', I)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE(MESSAGE,700) TREE_OFFSET(TOT_ET_QUANT)
  700 FORMAT(' Total ET Value: ', I)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      WRITE(MESSAGE,800) TREE_OFFSET(TOT_L2_QUANT)
  800 FORMAT(' Total L2 Value: ', I)
      CALL OUTMSG(MESSAGE(1:TRULEN(MESSAGE)))
C
      CALL PFWAIT()
C
  999 RETURN
      END
C
C
C
      SUBROUTINE SHO_ADCE()
C----------------------------------------------------------------------
C-
C-   Purpose and Methods : Display the contents of ADC_CNT_VS_RAW_E
C-
C-   Inputs  : none
C-   Outputs : none
C-   Controls: none
C-
C-   Created   5-SEP-1990   MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE
C-
C----------------------------------------------------------------------
      IMPLICIT NONE
C----------------------------------------------------------------------
C
C       Global Declarations
C
      INCLUDE 'D0$PARAMS:LEVEL1_LOOKUP.PARAMS'
      INCLUDE 'D0$INC:LEVEL1_LOOKUP.INC'
      INCLUDE 'LSMP$SOURCE:LEVEL1_LOOKUP_EXPANSION.INC'
      INTEGER  TRULEN
      EXTERNAL TRULEN
      LOGICAL  FULMOD
      EXTERNAL FULMOD
      INTEGER  READPF
      EXTERNAL READPF
      INTEGER  PFNUM
      EXTERNAL PFNUM
C
C       Local Variables
C
      INTEGER MAGN_ETA
      INTEGER PHI
      INTEGER COUNT
      CHARACTER*80 MESSAGE
      INTEGER ROWS
      INTEGER COLUMNS
      INTEGER KEY
      LOGICAL NO_WAIT
C
      NO_WAIT = .FALSE.
      CALL GETSCR(ROWS, COLUMNS)
      ROWS = (ROWS - 6) / 2
      COUNT = 1
      CALL PFLABL('MORE', 'NO WAIT', ' ', 'BACK')
      CALL OUTMSG(' SIGN_ETA MAGN_ETA PHI  EM CHANNEL  HD CHANNEL')
      DO PHI = PHI_MIN, PHI_MAX
        DO MAGN_ETA = ETA_RANGE_MIN, ETA_RANGE_MAX
          WRITE(MESSAGE, 100) MAGN_ETA, PHI, ADC_CNT_VS_RAW_E(POS_ETA,
     &      MAGN_ETA, PHI, EM_TOWER), ADC_CNT_VS_RAW_E(POS_ETA,
     &      MAGN_ETA, PHI, HD_TOWER)
  100     FORMAT(' PLUS     ', I8, ' ', I3, ' ', F11.5, ' ', F11.5)
          CALL OUTMSG(MESSAGE)
C
          WRITE(MESSAGE, 200) MAGN_ETA, PHI, ADC_CNT_VS_RAW_E(NEG_ETA,
     &      MAGN_ETA, PHI, EM_TOWER), ADC_CNT_VS_RAW_E(NEG_ETA,
     &      MAGN_ETA, PHI, HD_TOWER)
  200     FORMAT(' MINUS    ', I8, ' ', I3, ' ', F11.5, ' ', F11.5)
          CALL OUTMSG(MESSAGE)
          IF ((.NOT. NO_WAIT) .AND. (MOD(COUNT, ROWS) .EQ. 0) .AND.
     &      (FULMOD()) ) THEN
            CALL OUTMSG(' Press PF1 to see more.')
            KEY = READPF()
            IF (KEY .EQ. 4) GOTO 999
            IF (KEY .EQ. 2) NO_WAIT = .TRUE.
            CALL OUTMSG(' ')
            CALL OUTMSG(
     &        ' SIGN_ETA MAGN_ETA PHI  EM CHANNEL  HD CHANNEL')
          ENDIF
          COUNT = COUNT + 1
C
        END DO
      END DO
      CALL PFLABL('AGAIN', 'HELP', ' ', 'BACK')
      CALL PFWAIT()
C
  999 RETURN
      END
