        SUBROUTINE PDFSET(LU,IER,SET,HSET,D2)
C
C     PROGRAM TO DETERMINE THE HIGHEST EXISTING SET NUMBER AND
C     SET AN ERROR FLAG IF THE SET ENTERED (INPUT SET) IS TOO
C     LARGE OR TOO SMALL.
C
C     DELROSE WINTER   12-JUL-85
C   
C     **************************************************************
C
        INTEGER HSET,SET
        LOGICAL *1 MREF(26),MRNUM(10),D2(13)
        DATA MRNUM/'0','1','2','3','4','5','6','7','8','9'/
        DATA MREF/'D','R','1',':','[','3','7','7',',','3',
	1 '7','7',']','P','D','F','3',' ','.','B','I','N',4*' '/
C
        CALL ERRSET(29,.true.,.false.,.true.,.false.)  !supress message
C
	DO 10 I=1,13
10	MREF(I)=D2(I)
        DO 11 I=1,10
        MREF(18)=MRNUM(I)
        MREF(23)=0
        OPEN(UNIT=LU,NAME=MREF,TYPE='OLD',READONLY,ERR=15)
        CLOSE(UNIT=LU,ERR=17)
11      CONTINUE
        HSET=39
        GOTO 1
15      CALL ERRSNS(NERR)
        IF(NERR.NE.29)GOTO 17
        HSET=29+I-1
        GOTO 1
17      CALL EXIT
C
C
C    see if the set number desired is too big (greater than HSET), or
C    too small (smaller than 0) and set error flag IER accordingly.
C
1       IER=0                                  !initialize error flag
        IF(SET.LT.0)IER=6                      !set flag for set too low
        IF(SET.GT.HSET)IER=7                   !set flag for set too high
C 
        RETURN
        END
