     	SUBROUTINE IF_DCL
C
C	THIS ROUTINE PARSES THE DCL LINE DEFINED IN "GRAFIT.CLD".
C
     	CHARACTER PAR_FILE*32, DES_FILE*32, DAT_FILE*32
     	INTEGER   TERMID
     	LOGICAL   HARDCOPY, SKIPDI
     	COMMON/GRAFIT_CLD/ NFUNC, TERMID, HARDCOPY, SKIPDI,
     +  NFILES, DAT_FILE(16), PAR_FILE, DES_FILE
     	CHARACTER VALUE*64
     	LOGICAL   YES
     	INTEGER   CLI$PRESENT,  CLI$GET_VALUE
     	EXTERNAL  CLI$_NEGATED
C
C  INITIALIZE...
C
     	HARDCOPY = .FALSE.
     	SKIPDI   = .FALSE.
     	TERMID   = 0
     	NFUNC    = 0
     	NFILES   = 0
     	PAR_FILE = ' '
     	DES_FILE = ' '
     	DO I=1, 16
     	   DAT_FILE(I) = ' '
     	ENDDO
C
C  PARSE THE WHOLE INPUT LINE FIRST...
C
     	CALL CLI$GET_VALUE('$LINE',VALUE,N)
     	ISP = INDEX(VALUE(1:N),' ')
     	ISL = INDEX(VALUE(1:N),'/')
     	IF( ISP.EQ.0 .AND. ISL.EQ.0 ) RETURN
     	IF( ISP.GT.0 ) THEN
     	    ISL = INDEX('RUN',VALUE(1:ISP-1))
     	    IF( ISL.GT.0 ) RETURN
     	ENDIF
C
C  PARSE GRAPHICS FUNCTION...
C
     	IF( CLI$PRESENT('FUNCTION')
     +.AND. CLI$GET_VALUE('FUNCTION',VALUE,N) ) THEN
     	    IF( VALUE(1:1).EQ.'X' ) THEN
     		NFUNC = 1
     	    ELSE IF( VALUE(1:1).EQ.'L' ) THEN
     		NFUNC = 2
     	    ELSE IF( VALUE(1:1).EQ.'C' ) THEN
     		NFUNC = 3
     	    ELSE IF( VALUE(1:1).EQ.'H' ) THEN
     		NFUNC = 4
     	    ELSE IF( VALUE(1:1).EQ.'P' ) THEN
     		NFUNC = 5
     	    ELSE IF( VALUE(1:1).EQ.'T' ) THEN
     		NFUNC = 6
     	    ELSE IF( VALUE(1:1).EQ.'F' ) THEN
     		NFUNC = 7
     	    ELSE IF( VALUE(1:1).EQ.'D' ) THEN
     		NFUNC = 8
     	    ENDIF
     	ENDIF
C
C  PARSE HARDCOPY MODE...
C
     	IF( CLI$PRESENT('TERMINAL')
     +.AND. CLI$GET_VALUE('TERMINAL',VALUE,N) ) THEN
     	    IF( VALUE(1:1).EQ.'A' ) THEN
     		TERMID = 1
     	    ELSE IF( VALUE(1:1).EQ.'T' ) THEN
     		TERMID = 2
     	    ELSE
     		TERMID = 3
     	    ENDIF
     	ELSE IF(CLI$PRESENT('HARDCOPY').EQ.%LOC(CLI$_NEGATED)) THEN
     		SKIPDI = .TRUE.
     	ELSE IF( NFUNC.LT.6 ) THEN
     	    IF( CLI$PRESENT('HARDCOPY') .OR. CLI$PRESENT('DEVICE')
     +     .OR. CLI$PRESENT('SCALE')    .OR. CLI$PRESENT('OFFSET')
     +     .OR. CLI$PRESENT('HPAGE')    .OR. CLI$PRESENT('VPAGE')
     +     .OR. CLI$PRESENT('PAGE_FEED').OR. CLI$PRESENT('PEN_SPEED')
     +     .OR. CLI$PRESENT('COPIES')   .OR. CLI$PRESENT('ID') ) THEN
     		HARDCOPY = .TRUE.
     		TERMID   = 1
     		IF( NFUNC.EQ.0 ) NFUNC = 1
     		CALL IFINIT_ITM(TERMID)
     	    ENDIF
     	ENDIF
     	IF( NFUNC.GT.5 ) RETURN
C
C  GET INPUT FILE(S)...
C
     	IF( CLI$PRESENT('SETUP')
     +.AND. CLI$GET_VALUE('SETUP',VALUE,N) ) THEN
     	    IF(N.GT.32) CALL IF_DCL_STOP_N( N, VALUE )
     	    INQUIRE( FILE=VALUE, EXIST=YES )
     	    IF(.NOT.YES) CALL IF_DCL_STOP_F( N, VALUE )
     	    PAR_FILE = VALUE(1:32)
     	ENDIF

     	IF( CLI$PRESENT('LAYOUT')
     +.AND. CLI$GET_VALUE('LAYOUT',VALUE,N) ) THEN
     	    IF(N.GT.32) CALL IF_DCL_STOP_N( N, VALUE )
     	    INQUIRE( FILE=VALUE, EXIST=YES )
     	    IF(.NOT.YES) CALL IF_DCL_STOP_F( N, VALUE )
     	    DES_FILE = VALUE(1:32)
     	ENDIF

     	IF( CLI$PRESENT('P1') ) THEN
     	    DO I=1, 16
     		IF( CLI$GET_VALUE('P1',VALUE,N) ) THEN
     		    IF(N.GT.32) CALL IF_DCL_STOP_N(N,VALUE)
     		    INQUIRE( FILE=VALUE, EXIST=YES )
     		    IF(.NOT.YES) CALL IF_DCL_STOP_F(N,VALUE)
     		    NFILES = NFILES + 1
     		    DAT_FILE(NFILES) = VALUE(1:32)
     		ELSE
     		    GOTO 111
     		ENDIF
     	    ENDDO
     	ENDIF
111	IF( HARDCOPY .AND. NFILES.EQ.0 ) THEN
     	    STOP '%IF_DCL: missing filename for hardcopy'
     	ENDIF
     	RETURN
     	END

     	SUBROUTINE IF_DCL_STOP_N( N, VALUE )
     	CHARACTER VALUE*(*)
     	WRITE(6,1000) VALUE(1:N)
1000	FORMAT(' %IF_DCL: filename ',A<N>,' longer than 32 chars.')
     	CALL EXIT
     	END

     	SUBROUTINE IF_DCL_STOP_F( N, VALUE )
     	CHARACTER VALUE*(*)
     	WRITE(6,1000) VALUE(1:N)
1000	FORMAT(' %IF_DCL: can not find file ',A<N>)
     	CALL EXIT
     	END

     	LOGICAL FUNCTION IF_DCL_HARDCOPY()

     	CHARACTER PAR_FILE*32, DES_FILE*32, DAT_FILE*32
     	INTEGER   TERMID
     	LOGICAL   HARDCOPY, SKIPDI
     	COMMON/GRAFIT_CLD/ NFUNC, TERMID, HARDCOPY, SKIPDI,
     +  NFILES, DAT_FILE(16), PAR_FILE, DES_FILE

     	IF_DCL_HARDCOPY = HARDCOPY
     	RETURN
     	END

     	LOGICAL FUNCTION IF_DCL_SKIPDI()

     	CHARACTER PAR_FILE*32, DES_FILE*32, DAT_FILE*32
     	INTEGER   TERMID
     	LOGICAL   HARDCOPY, SKIPDI
     	COMMON/GRAFIT_CLD/ NFUNC, TERMID, HARDCOPY, SKIPDI,
     +  NFILES, DAT_FILE(16), PAR_FILE, DES_FILE

     	IF_DCL_SKIPDI = SKIPDI
     	RETURN
     	END

     	SUBROUTINE IF_DCL_NFILE( NF )

     	CHARACTER PAR_FILE*32, DES_FILE*32, DAT_FILE*32
     	INTEGER   TERMID
     	LOGICAL   HARDCOPY, SKIPDI
     	COMMON/GRAFIT_CLD/ NFUNC, TERMID, HARDCOPY, SKIPDI,
     +  NFILES, DAT_FILE(16), PAR_FILE, DES_FILE

     	NF = NFILES
     	NFILES = 0
     	RETURN
     	END

     	SUBROUTINE IF_DCL_CRT( IT )

     	CHARACTER PAR_FILE*32, DES_FILE*32, DAT_FILE*32
     	INTEGER   TERMID
     	LOGICAL   HARDCOPY, SKIPDI
     	COMMON/GRAFIT_CLD/ NFUNC, TERMID, HARDCOPY, SKIPDI,
     +  NFILES, DAT_FILE(16), PAR_FILE, DES_FILE

     	IT = TERMID
     	RETURN
     	END

     	SUBROUTINE IF_DCL_FUNCTION( IF )

     	CHARACTER PAR_FILE*32, DES_FILE*32, DAT_FILE*32
     	INTEGER   TERMID
     	LOGICAL   HARDCOPY, SKIPDI
     	COMMON/GRAFIT_CLD/ NFUNC, TERMID, HARDCOPY, SKIPDI,
     +  NFILES, DAT_FILE(16), PAR_FILE, DES_FILE

     	IF = NFUNC
     	RETURN
     	END

     	SUBROUTINE IF_DCL_FILE( IT, FNAME )

     	CHARACTER PAR_FILE*32, DES_FILE*32, DAT_FILE*32
     	INTEGER   TERMID
     	LOGICAL   HARDCOPY, SKIPDI
     	COMMON/GRAFIT_CLD/ NFUNC, TERMID, HARDCOPY, SKIPDI,
     +  NFILES, DAT_FILE(16), PAR_FILE, DES_FILE
     	CHARACTER FNAME*(*)

     	ITT = IT
     	IF( ITT.GT.NFILES ) ITT = NFILES
     	IF( ITT.LT.1 ) ITT = 1
     	FNAME = DAT_FILE(ITT)
     	DAT_FILE(ITT) = ' '
     	RETURN
     	END

     	SUBROUTINE IF_DCL_SETUP( FNAME )

     	CHARACTER PAR_FILE*32, DES_FILE*32, DAT_FILE*32
     	INTEGER   TERMID
     	LOGICAL   HARDCOPY, SKIPDI
     	COMMON/GRAFIT_CLD/ NFUNC, TERMID, HARDCOPY, SKIPDI,
     +  NFILES, DAT_FILE(16), PAR_FILE, DES_FILE
     	CHARACTER FNAME*(*)

     	FNAME = PAR_FILE
     	PAR_FILE = ' '
     	RETURN
     	END

     	SUBROUTINE IF_DCL_LAYOUT( FNAME )

     	CHARACTER PAR_FILE*32, DES_FILE*32, DAT_FILE*32
     	INTEGER   TERMID
     	LOGICAL   HARDCOPY, SKIPDI
     	COMMON/GRAFIT_CLD/ NFUNC, TERMID, HARDCOPY, SKIPDI,
     +  NFILES, DAT_FILE(16), PAR_FILE, DES_FILE
     	CHARACTER FNAME*(*)

     	FNAME = DES_FILE
     	DES_FILE = ' '
     	RETURN
     	END

