      SUBROUTINE GEN_ALL_PROMS()
C----------------------------------------------------------------------
C-
C-   Purpose and Methods : Prompt for a directory and whether to create a
C-   binary and/or Intellec format file. Then create PROM files for all towers
C-   that are defined (that have DAC_BYTE non-zero).
C-
C-   Inputs  : none
C-   Outputs : none
C-   Controls: none
C-
C-   Created  12-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
      INTEGER  PFNUM
      EXTERNAL PFNUM
C
C       Local variables
C
      INTEGER SIGN_ETA, ETA, PHI, PROM, CHANNEL
      INTEGER LENGTH
      CHARACTER*40 DIRECTORY
      SAVE DIRECTORY
      DATA DIRECTORY / ' ' /
      CHARACTER*120 FILE_NAME
      INTEGER REVISION_NUMBER
      SAVE REVISION_NUMBER
      DATA REVISION_NUMBER / 6 /
      LOGICAL MAKE_BINARY
      LOGICAL MAKE_INTELLEC
      DATA MAKE_BINARY / .TRUE. /, MAKE_INTELLEC / .FALSE. /
      INTEGER PROM_TABLE(2048)
C
      INTEGER NUM_PARAMS
      PARAMETER ( NUM_PARAMS = 4 )
      CHARACTER*33 LABELS(NUM_PARAMS)
      DATA LABELS / 'Directory', 'Revision number', 'Make binary file',
     &  'Make Intellec file' /
      CHARACTER*1 TYPARR(NUM_PARAMS)
      DATA TYPARR / 'C', 'I', 'L', 'L' /
      INTEGER LIMITS(2, NUM_PARAMS)
      DATA LIMITS / 0, 0,  0, 99,  0, 0, 0, 0 /
C
      INTEGER UNIT_NUM
      INTEGER ROUTINE_ID
      PARAMETER (ROUTINE_ID = 521)
      INTEGER PAGE_LENGTH
      PARAMETER (PAGE_LENGTH = 256)
      INTEGER IERR
C
C       Get the parameters
C
      CALL GETDIS(NUM_PARAMS, LABELS, TYPARR, LIMITS, DIRECTORY,
     &  REVISION_NUMBER, MAKE_BINARY, MAKE_INTELLEC)
      IF (PFNUM() .NE. 0) GOTO 999
C
      IF ((.NOT. MAKE_BINARY) .AND. (.NOT. MAKE_INTELLEC)) THEN
        CALL OUTMSG(' No files to make.')
        CALL PFWAIT()
        GOTO 999
      ENDIF
C
C       Get a unit number
C
      CALL GTUNIT(ROUTINE_ID, UNIT_NUM, IERR)
      IF (IERR .NE. 0) CALL ABORT(
     &  'Error calling GTUNIT in GEN_ALL_PROMS')
C
C       Loop over all the coordinates
C
      DO PROM = EM_PROM, PY_PROM
        DO PHI = PHI_MIN, PHI_MAX
          DO ETA = ETA_RANGE_MIN, ETA_RANGE_MAX
            DO SIGN_ETA = POS_ETA, NEG_ETA
              IF ((PROM .EQ. EM_PROM) .AND.
     &          (DAC_BYTE(SIGN_ETA, ETA, PHI, EM_TOWER) .EQ. 0)) THEN
                GOTO 1000               ! Repeat loop
              ELSEIF ((PROM .EQ. HD_PROM) .AND.
     &          (DAC_BYTE(SIGN_ETA, ETA, PHI, HD_TOWER) .EQ. 0)) THEN
                GOTO 1000               ! Repeat loop
              ELSEIF (((PROM .EQ. PX_PROM) .OR. (PROM .EQ. PY_PROM))
     &          .AND. ((DAC_BYTE(SIGN_ETA, ETA, PHI, EM_TOWER) .EQ. 0)
     &           .OR.  (DAC_BYTE(SIGN_ETA, ETA, PHI, HD_TOWER) .EQ. 0)))
     &          THEN
                GOTO 1000               ! Repeat loop
              ENDIF
C
              IF (PROM .EQ. EM_PROM) THEN
                CALL GENERATE_PROM_TABLE_EM(SIGN_ETA, ETA, PHI,
     &            PROM_TABLE, PAGE_LENGTH)
                FILE_NAME = 'CEM'
              ELSEIF (PROM .EQ. HD_PROM) THEN
                CALL GENERATE_PROM_TABLE_HD(SIGN_ETA, ETA, PHI,
     &            PROM_TABLE, PAGE_LENGTH)
                FILE_NAME = 'CHD'
              ELSEIF (PROM .EQ. PX_PROM) THEN
                CALL GENERATE_PROM_TABLE_PX(SIGN_ETA, ETA, PHI,
     &            PROM_TABLE, PAGE_LENGTH)
                FILE_NAME = 'CPX'
              ELSEIF (PROM .EQ. PY_PROM) THEN
                CALL GENERATE_PROM_TABLE_PY(SIGN_ETA, ETA, PHI,
     &            PROM_TABLE, PAGE_LENGTH)
                FILE_NAME = 'CPY'
              ENDIF
C
              IF (SIGN_ETA .EQ. POS_ETA) THEN
                FILE_NAME(4:4) = 'P'
              ELSE
                FILE_NAME(4:4) = 'N'
              ENDIF
C
              WRITE(FILE_NAME(5:), 100) ETA, PHI, REVISION_NUMBER
  100         FORMAT( I2.2, I2.2, '_CTFE_PROM.BIN', I2.2)
C
              LENGTH = TRULEN(DIRECTORY)
              IF ((LENGTH .GE. 1) .AND. (LENGTH .LT. 40) .AND.
     &          (DIRECTORY(LENGTH:LENGTH) .NE. ':') .AND.
     &          (DIRECTORY(LENGTH:LENGTH) .NE. ']')) THEN
                DIRECTORY(LENGTH+1:LENGTH+1) = ':'
              ENDIF
C
              FILE_NAME = DIRECTORY(1:TRULEN(DIRECTORY)) //
     &          FILE_NAME(1:TRULEN(FILE_NAME))
C
              CALL WRITE_PROM_FILE(UNIT_NUM, FILE_NAME, PROM_TABLE,
     &          PROM, MAKE_BINARY, MAKE_INTELLEC)
C
 1000         CONTINUE
            END DO
          END DO
        END DO
      END DO
C
 2000 CONTINUE
      CALL PFWAIT()
C
  999 RETURN
      END
C

