     	SUBROUTINE IFFEED( ARRAY, PLOTID, OUTPUT )
C
C  PROGRAMMER: R.S. ZHOU		SEP-1986
C
C	THIS ROUTINE DUMPS THE HARDCOPY.
C
C	ARRAY --- ARRAY THAT CONTAINS THE INITIALIZATON PARAMETERS.
C
C	ARRAY(1): HARDCOPY DEVICE NUMBER.
C
C		1 => HP7550 PEN PLOTTER
C		2 => HP7221 PEN PLOTTER
C		3 => IMAGE/SLIDE  MAKER
C		4 => POSTSCRIPT PRINTER
C
C	ARRAY(2): NUMBER OF HARDCOPIES.
C	ARRAY(3): PLOT ID FLAG.
C	ARRAY(4): PAGE FEED FLAG.
C	ARRAY(5): HARDCOPY SETUP PARAMETER 1 (OFFSET X).
C	ARRAY(6): HARDCOPY SETUP PARAMETER 2 (OFFSET Y).
C	ARRAY(7): HARDCOPY SETUP PARAMETER 3 (SCALE  X).
C	ARRAY(8): HARDCOPY SETUP PARAMETER 4 (SCALE  Y).
C	........  ........
C	ARRAY(20): HARDCOPY SETUP PARAMETER 16.
C
C	PLOTID: PLOT ID LABEL
C	OUTPUT: OPTIONAL HARDCOPY DESTINATION
C
     	INCLUDE   'TEKLIB.CBS'
     	CHARACTER HCNAME*80, PRINT*16, IMAGE*16, PLOTID*(*), OUTPUT*(*)
     	DIMENSION SETUP(20), ARRAY(1)
     	DATA SETUP/ 1.,1.,1.,1.,0,0,1.,1.,1.,0,5.,1.,1.,0,0,0,0,0,0,0 /

     	IF( ARRAY(1).NE.0.0 ) THEN
     	    DO  I=1, 20
     		SETUP(I) = ARRAY(I)
     	    ENDDO
     	ENDIF
     	IF(IF_DCL_HARDCOPY()) CALL IFFEED_SETUP(SETUP(1),PLOTID,OUTPUT)
     	IF( IDF.EQ.0 ) THEN
     	    CALL IFANSI_VIDEO(70)
     	    WRITE(6,4321)
4321	    FORMAT('_oops: Missing hardcopy meta-file.')
     	    RETURN
     	ENDIF
     	IDEV = SETUP(1)+0.1
     	IF( IDEV.LT.1 ) IDEV = 1
     	IF( IDEV.GT.4 ) IDEV = 4
C
C  DUMP THE LAST "PLOT" BUFFER IF AT ALL...
C
     	IF( NPPS.GT.0 ) CALL IFPLOT_DUMP
C
C  GET THE CURRENT GRAPH ORIGIN...
C
     	XORG = SETUP(5) + FLOAT(IXO)/FUNI
     	YORG = SETUP(6) + FLOAT(IYO)/FUNI
C
C  WRAP UP THE "DI" FILE...
C
     	IF( SETUP(3).NE.0.0 .AND. PLOTID.NE.' ' ) THEN	!PLOT ID
     	    L1 = IFMISC_LENG( PLOTID )
     	    WRITE(IDF,1000) -XORG-XORS, -YORG-YORS, L1, PLOTID
     	ENDIF
1000	FORMAT('SPEN:  1'/
     +'PLOT:',2F6.3,'-3 0.000 1.000 2 0.000 0.000 3 3.000 0.000 2'/
     +'TEXT:',I3,'   0.050   0.050   0.080   0.080   0.000,',A<L1>)
     	WRITE(IDF,1001) INT(SETUP(4))
1001	FORMAT('FEED:',I3)
C
C  GET THE COMPLETE NAME OF DI FILE...
C
     	INQUIRE( UNIT=IDF, NAME=DINAME )
     	CLOSE(UNIT=IDF)
     	IDW = 0
C
C  OPEN A BATCH COMMAND FILE...
C
     	DTNAME = DINAME
     	CALL IFMISC_NAMEXT( DTNAME, '.BC' )
     	OPEN(UNIT=IDF,FILE=DTNAME,STATUS='NEW',FORM='FORMATTED',
     +       CARRIAGECONTROL='LIST')
C
C  GET THE HARDCOPY DRIVER...
C
     	HCNAME = DINAME
     	IF( IDEV.EQ.1 ) THEN			!HP7550 PEN PLOTTER
     	    CALL IFMISC_NAMEXT( HCNAME, '.HP' )
     	    IMAGE = 'HP7550.EXE'
     	    PRINT = 'HP_PRINT'
     	ELSE IF( IDEV.EQ.2 ) THEN		!HP7221 PEN PLOTTER
     	    CALL IFMISC_NAMEXT( HCNAME, '.HP' )
     	    IMAGE = 'HP7221.EXE'
     	    PRINT = 'HP_PRINT'
     	ELSE IF( IDEV.EQ.3 ) THEN		!IMAGE/SLIDE MAKER
     	    CALL IFMISC_NAMEXT( HCNAME, '.IM' )
     	    IMAGE = 'IMAGEM.EXE'
     	    PRINT = 'IM_PRINT'
     	ELSE IF( IDEV.EQ.4 ) THEN		!POSTSCRIPT PRINTER
     	    CALL IFMISC_NAMEXT( HCNAME, '.PS' )
     	    IMAGE = 'LN03PS.EXE'
     	    PRINT = 'PS_PRINT'
     	ENDIF
     	IF( OUTPUT.NE.' ' ) HCNAME = OUTPUT
C
C  WRITE THE COMMAND FILE FOR BATCHJOB...
C
     	NCOPY = SETUP(2)+0.1
     	IF( NCOPY.LT.1 ) NCOPY = 1
     	IF( NCOPY.GT.99) NCOPY = 99
     	L1 = IFMISC_LENG( DINAME )
     	L2 = IFMISC_LENG( HCNAME )
     	L3 = IFMISC_LENG(  IMAGE )
     	L4 = IFMISC_LENG(  PRINT )
     	WRITE(IDF,2000) IMAGE,DINAME,HCNAME,(SETUP(I),I=5,20),DINAME
2000	FORMAT('$! GRAFIT hardcopy command file.'/
     +'$ RUN GRAFIT$EXE:',A<L3>,/		!EXECUTE THE DRIVER
     +,A<L1>,/					!INPUT TO DRIVER
     +,A<L2>,/					!OUTPUT FROM DRIVER
     +'INIT:',16F7.2,/
     +'$ DELETE ',A<L1>)			!DELETE THE DI FILE
     	IF( OUTPUT.EQ.' ' ) THEN
     	IF( NCOPY.LT.2 ) THEN			!PRINT THE HARDCOPY
     	    WRITE(IDF,2001) PRINT, HCNAME
2001	    FORMAT('$ ',A<L4>,X,A<L2>)
     	ELSE
     	    L1 = 1
     	    IF( NCOPY.GT.9 ) L1 = 2
     	    WRITE(IDF,2002) PRINT, HCNAME, NCOPY
2002	    FORMAT('$ ',A<L4>,X,A<L2>,'/COPIES=',I<L1>)
     	ENDIF
     	ENDIF
     	CLOSE( UNIT=IDF )
C
C  SPAWN A PROCESS TO DUMP THE HARDCOPY...
C
     	DINAME = '$ SUB_PRINT'
     	DINAME(13:) = DTNAME
     	IDF = 37				!bit mask: 100101
     	CALL IFMISC_SPAWN( DINAME, IDF )
     	IDF = 0
     	WRITE(6,1234)
1234	FORMAT('_%SPAWN: hardcopy submitted to the plot queue')
     	RETURN
     	END

     	SUBROUTINE IFFEED_SETUP( SETUP, PLOTID, OUTPUT )
C
C	THIS ROUTINE PARSES THE DCL LINE DEFINED IN "GRAFIT.CLD"
C	FOR SOME HARDCOPY PAGE SETUP PARAMETERS.
C
     	CHARACTER PLOTID*(*), OUTPUT*(*)
     	DIMENSION SETUP(1)
     	CHARACTER VALUE*32
     	INTEGER   CLI$PRESENT,  CLI$GET_VALUE
     	EXTERNAL  CLI$_NEGATED
C
C  PARSE OPTIONAL HARDCOPY DESTINATION (/HARDCOPY[=destination])...
C
     	OUTPUT = ' '
     	IF( CLI$GET_VALUE('HARDCOPY',VALUE,N) ) OUTPUT = VALUE
C
C  PARSE PLOT ID...
C
     	IF( CLI$PRESENT('ID') ) THEN
     	    SETUP(3) = 1.0
     	    IF( CLI$GET_VALUE('ID',VALUE,N) ) PLOTID = VALUE
     	ENDIF
     	IF( CLI$PRESENT('ID').EQ.%LOC(CLI$_NEGATED) ) SETUP(3)=0.0
C
C  PARSE HARDCOPY DEVICE...
C
     	IF( CLI$PRESENT('DEVICE')
     +.AND. CLI$GET_VALUE('DEVICE',VALUE,N) ) THEN
     	    IF( VALUE(1:4).EQ.'HP75' ) THEN
     		IP = 1
     	    ELSE IF( VALUE(1:4).EQ.'HP72' ) THEN
     		IP = 2
     	    ELSE IF( VALUE(1:1).EQ.'S' ) THEN
     		IP = 3
     	    ELSE
     		IP = 4
     	    ENDIF
     	    SETUP(1) = FLOAT(IP)
     	ENDIF
C
C  PARSE HARDCOPY NUMBER...
C
     	IF( CLI$PRESENT('COPIES')
     +.AND. CLI$GET_VALUE('COPIES',VALUE,N) ) THEN
     	    DECODE( N, 111, VALUE, ERR=888 ) IP
111	    FORMAT(I)
     	    IF( IP.LT.1 .OR. IP.GT.99 ) GOTO 888
     	    SETUP(2) = FLOAT(IP)
     	ENDIF
C
C  PARSE PAGE_FEED FLAG...
C
     	IF(CLI$PRESENT('PAGE_FEED')) SETUP(4) = 1.0
     	IF(CLI$PRESENT('PAGE_FEED').EQ.%LOC(CLI$_NEGATED)) SETUP(4)=0.0
C
C  PARSE PLOT OFFSET...
C
     	IF( CLI$PRESENT('OFFSET') ) THEN
     	    DO I=1, 2
     	    IF( CLI$GET_VALUE('OFFSET',VALUE,N) ) THEN
     		DECODE( N, 222, VALUE, ERR=888 ) PP
222		FORMAT(F10.0)
     		SETUP(4+I) = PP
     	    ENDIF
     	    ENDDO
     	ENDIF
C
C  PARSE PLOT OVERALL SCALE FACTORS...
C
     	IF( CLI$PRESENT('SCALE') ) THEN
     	    DO I=1, 2
     	    IF( CLI$GET_VALUE('SCALE',VALUE,N) ) THEN
     		DECODE( N, 222, VALUE, ERR=888 ) PP
     		IF( PP.LE.0.0 .OR. PP.GT.3.0 ) GOTO 888
     		SETUP(6+I) = PP
     	    ENDIF
     	    ENDDO
     	ENDIF
C
C  PARSE PAGE ALIGNMENT FLAG...
C
     	IF( CLI$PRESENT('HPAGE') ) SETUP(10) = 0.0
     	IF( CLI$PRESENT('VPAGE') ) SETUP(10) = 1.0
C
C  PARSE PEN_SPEED...
C
     	IF( CLI$PRESENT('PEN_SPEED')
     +.AND. CLI$GET_VALUE('PEN_SPEED',VALUE,N) ) THEN
     	    DECODE( N, 111, VALUE, ERR=888 ) IP
     	    IF( IP.LT.1 .OR. IP.GT.9 ) GOTO 888
     	    SETUP(11) = IP
     	ENDIF
     	RETURN
888	WRITE(6,999) VALUE(1:N)
999	FORMAT('_%IF_DCL: invalid parameter ',A<N>)
     	CALL EXIT
     	END

