      SUBROUTINE GETSPEC3(USED,TYPTBL,REG,IBXN,NTYP,NDIMB,NDIMB1)
C
C  To read and check regression definitions
C
      INTEGER*2 TYPTBL(0:NTYP,0:NTYP),
     * REG(NTYP+NTYP*(NTYP+1)/2,2*NDIMB+4),IBXN(2*NDIMB)
      INTEGER REGINDX
      LOGICAL USED(NDIMB)
C
      MAXXTYP= NTYP+NTYP*(NTYP+1)/2
      DO 1 I=1,NTYP
      TYPTBL(0,I)= I
    1 TYPTBL(I,0)= I
      K= NTYP
      DO 2 I=1,NTYP
      DO 2 J=I,NTYP
      K=K+1
      TYPTBL(I,J)= K
    2 TYPTBL(J,I)= K
      DO 3 I=1,NDIMB
    3 USED(I)= (NTYP.LT.0)
      K= 2*NDIMB+4
      DO 4 I=1,MAXXTYP
    4 REG(I,K)= 0
C
      DO 10 I=1,MAXXTYP
      READ(7,'(3I4)',ERR=51,END=51) IT1,IT2,IDIM
      IF (IT1.GT.IT2) THEN
        J=IT2
        IT2= IT1
        IT1= J
      ENDIF
      REGINDX= 0
      IF (IDIM.GE.0.AND.IDIM.LE.NDIMB.AND.IT2.GE.1.AND.IT2.LE.NTYP
     * .AND.IT1.GE.0.AND.IT1.LE.NTYP) REGINDX= TYPTBL(IT1,IT2)
      IF (REGINDX.GT.0.AND.REG(REGINDX,K).EQ.0) THEN
        IF (IDIM.GT.0) THEN
          READ(7,'(40I2)',ERR=51,END=51) (IBXN(J),J=1,2*IDIM)
          DO 7 J= 1,2*IDIM,2
          IF (IBXN(J).LE.0.OR.IBXN(J+1).LE.0.OR.IBXN(J).GT.NDIMB.OR.
     *     IBXN(J+1).GT.NDIMB1) GOTO 51
    7     CONTINUE
          DO 8 J=1,IDIM
          REG(REGINDX,J+3)= IBXN(2*J-1)
          REG(REGINDX,J+NDIMB+3)= IBXN(2*J)
    8     USED(IBXN(2*J-1))= (IDIM.GT.0)
        ENDIF
        REG(REGINDX,1)= IT1
        REG(REGINDX,2)= IT2
        REG(REGINDX,3)= IDIM
        REG(REGINDX,K)= 1
      ELSE
        GOTO 51
      ENDIF
   10 CONTINUE
C
      DO 14 I=1,MAXXTYP
      IF (REG(I,K).EQ.0) THEN
        WRITE(*,'(A,I3,A)')
     *   ' PROGRAM TERMINATED: All required regressions (',MAXXTYP,
     *   ') not defined'
        WRITE(9,'(A,I3,A)')
     *   ' PROGRAM TERMINATED: All required regressions (',MAXXTYP,
     *   ') not defined'
        STOP
      ENDIF
   14 CONTINUE
      DO 15 I=1,NDIMB
      IF (.NOT.USED(I)) THEN
        WRITE(*,'(A,I2,A)') ' PROGRAM TERMINATED: Beta parameter (',I,
     *   ') not used in any regression'
        WRITE(9,'(A,I2,A)') ' PROGRAM TERMINATED: Beta parameter (',I,
     *   ') not used in any regression'
        STOP
      ENDIF
   15 CONTINUE
      CLOSE (7)
C
      WRITE(9,'(/A/A)') ' The model (defined regressions):',
     * '   Classes   B*X'
      DO 20 IT=1,MAXXTYP
   20 WRITE(9,'(I6,I3,7(I5,A,I2),9(/9X,7(I5,A,I2)))') REG(IT,1),
     * REG(IT,2),(REG(IT,I),'*',REG(IT,I+NDIMB),I=4,REG(IT,3)+3)
      RETURN
C
   51 WRITE(*,'(2A/2A/2A,I4,A)') ' PROGRAM TERMINATED: A regression ',
     * 'was incorrectly defined, an attempt was',' made to define the ',
     * 'same regression twice, or the end-of-file was read',' before', 
     * ' the required',MAXXTYP,' regression definitions were read.'
      WRITE(9,'(2A/2A/A,I4,A)') ' PROGRAM TERMINATED: A regression ',
     * 'was incorrectly defined, an attempt was made',' to define the ',
     * 'same regression twice, or the end-of-file was read before the',
     * ' required',MAXXTYP,' regression definitions were read.'
      STOP
      END
     