     	PROGRAM DRIVER
C
C  PROGRAMMER:  RONG-SHENG ZHOU
C
C		212 DEVLIN HALL
C		CHEMISTRY DEPARTMENT
C		BOSTON COLLEGE, 8/1988
C		CHESTNUT HILL, MA 02167
C		TEL: (607)-552-3905/8481
C
C	THIS ROUTINE READS A DEVICE-INDEPENDENT HARDCOPY FILE
C	WRITTEN BY "TEKLIB" PLOTTING LIBRARY AND GENERATE A 
C	DEVICE-DEPENDENT HARDCOPY FILE DEPENDING ON THE DRIVER
C	LIBRARY IT IS LINKED TO.
C
C	THE FORMAT OF THE DEVICE-INDEPENDENT HARDCOPY FILE
C	IS A KEYWORD-ORIENTED SEQUENTIAL ACCESS ASCII FILE.
C	THE FOLLOWING IS A LIST OF KEYWORDS IMPLEMENTED FOR 
C	THE DI FILE (NUMBERS IN [] SIGNIFIES DEFAULT PARAMETER
C	VALUES WHEN THE KEYWORD IS MISSING FROM THE DI FILE):
C
C %001	INIT: (SETUP(I),I=1,16) ...... (A4,X,16F7.2)
C
C		The 1st keyword in the file, where SETUP array contains 
C		maximum 16 device-specific setup parameters for the 
C		intended hardcopy device. Refer to subroutine "IFINIT"
C		in the corresponding device library for details.
C		Subroutine call is "IFINIT".
C
C %002	FEED: PAGE-FEED-FLAG [1] ...... (A4,X,I3)
C
C		The last keyword in a hardcopy plot.
C		PAGE-FEED-FLAG=0: plot page feed NO.
C		PAGE-FEED-FLAG=1: plot page feed YES.
C		Subroutine call is "IFFEED".
C		After keyword FEED, another hardcopy plot could follow.
C
C %003  STAR: XORG, YORG ...... (A4,X,2F8.3)
C
C		PLOT SESSION INITIALIZATION.
C
C %003	SCAL: X-SCALE-FACTOR,Y-SCALE-FACTOR [1.0,1.0] .... (A4,X,2F8.3)
C
C		Overall scale factor of graph.
C		Subroutine call is "IFSCAL".
C
C %004	ROTA: X-ANGLE,Y-ANGLE [0.0,0.0] ...... (A4,X,2F8.3)
C
C		Graph rotation instruction where
C
C		X-ANGLE: X-axis rotation angle in degrees.
C		Y-ANGLE: Y-axis rotation angle in degrees.
C
C		Counter clockwise -> positive angle.
C		Subroutine call is "IFROTA".
C
C %005	STYL: LTYP,LWID [1,1] ...... (A4,X,2I3)
C
C		Select active plotting stylus (linetype and linewidth)
C		where applied for subsequent vectors.
C		Subroutine call is "IFSTYL".
C
C %006	FILL: FILL-PATTERN [0] ...... (A4,X,I3)
C
C		If FILL-PATTERN is not zero, begin polygon fill or area
C		shading for subsequent vectors. To terminate the filling.
C		issue a FILL keyword with a FILL-PATTERN of zero.
C
C		FILL-PATTERN>0: edge/outline the filled area.
C		FILL-PATTERN<0: do not edge/outline the filled area.
C
C		Subroutine call is "IFFILL".
C
C %007	FONT: FONT-NUMBER [1] ...... (A4,X,I3)
C
C		Select active font for subsequent text layout.
C
C		FONT-NUMBER=1: standard font as defined in "IFINIT".
C		FONT-NUMBER=2: italic standard font.
C		FONT-NUMBER=3: boldface standard font.
C
C		Font size is mapped from text-width in text drawing routine.
C		Subroutine call is "IFFONT".
C
C %008	SPEN: PEN/COLOR CODE [1] ...... (A4,X,I3)
C
C		Select active pen or color for subsequent drawing
C		of vectors and text.
C		Subroutine call is "IFSPEN".
C
C %010	PLOT: (XP(I),YP(I),IP(I),I=1,9) ...... (A4,X,5(2F6.3,I2))
C
C		Vector generation instructions, where XP(I), YP(I) are
C		vector end-point coordinates in inches referring to
C		the active graph origin and IP(I) signifies the action
C		to perform:
C
C		IP(I)= 2: draw to XP(I),YP(I) (pen down).
C		IP(I)= 3: move to XP(I),YP(I) (pen up).
C		IP(I)=-3: move and reorigin to XP(I),YP(I).
C		IP(I)=-9: reorigin to XP(I),YP(I) only.
C
C		IP(I)=0 signifies the end of the current vector group
C		if the line contains less than five vectors. The active
C		plotting stylus is used to generate the vectors.
C		Subroutine call is "IFPLOT".
C
C %011	TEXT: TL,XP,YP,WW,HH,RA,(TS(I),I=1,TL) ...... (A4,X,I3,5F8.3,A80)
C
C		Text generation instruction, where
C
C		TL: Length of textstring in number of characters.
C		XP: X-coordinate in inches (lower left corner of text).
C		YP: Y-coordinate in inches (lower left corner of text).
C		WW: width of textstring in inches.
C		HH: Height of textstring in inches.
C		RA: Rotation of textstring in degrees (counter clockwise).
C		TS: Textstring in character format.
C
C		For devices that does not support continuous fontsize,
C		internal mapping of text width to predefined fonts is 
C		used. For devices that does not support independent
C		text height, only text width is used. For devices that
C		does not support textstring rotation, rotated text is
C		ignored. Notice that a pair of lines are used for each
C		textstring to be drawn.
C		Subroutine call is "IFTEXT".
C
C %013	MARK: SP,DI,XP,YP,RA ...... (A4,X,I3,4F8.3)
C
C		Graphic marker symbol generation instruction, where
C
C		SP: symbol pointer to symbol table.
C		DI: Diameter of symbol in inches.
C		XP: X-coordinate of symbol center in inches.
C		YP: Y-coordinate of symbol center in inches.
C		RA: Rotation of symbol around its center
C		    in degrees (counter clockwise).
C
C		Subroutine call is "IFMARK".
C
C %014	BARS: BL,BH,BW,XP,YP,RA ...... (A4,X,6F8.3)
C
C		Bar generation instruction, where
C
C		BL: bar length in inches in x-axis.
C		BH: bar height in inches in y-axis.
C		BW: bar border width in inches.
C		XP: center of bar in inches (X).
C		YP: center of bar in inches (Y).
C		RA: rotation angle of bar in degrees.
C
C		Subroutine call is "IFBARS".
C
C %015	ARCS: R1,R2,BW,XP,YP,A0,A1,A2,CA ...... (A4,X,9F8.3)
C
C		Arc/circle/ellipse/pie generation instruction, where
C
C		R1: radius of arc in inches in x-axis.
C		R2: radius of arc in inches in y-axis.
C		BW: arc border width in inches.
C		XP: x-coordinate of arc center in inches.
C		YP: y-coordinate of arc center in inches.
C		A0: arc rotation angle in degrees.
C		A1: beginning angle of arc in degrees.
C		A2: ending angle of arc in degrees.
C		CA: chord angle in degrees [10.0].
C
C		Subroutine call is "IFARCS".
C
C %016	ARRH: TY,LL,WW,HL,XP,YP,RA ...... (A4,X,I3,6F8.3)
C
C		Arrowhead generation instruction, where
C
C		TY: type of arrowhead.
C		LL: overall length of arrowhead in inches.
C		WW: overall width of arrowhead in inches.
C		HL: head-section lenght in inches.
C		XP: x-coordinate of the head tip in inches.
C		YP: y-coordinate of the head tip in inches.
C		RA: rotation angle in degrees.
C
C		Subroutine call is "IFARRH".
C
C %017	POLY: NS,DI,BW,XP,YP,RA ...... (A4,X,I3,5F8.3)
C
C		Polygon generation instruction, where
C
C		NS: number of sides/edges of polygon.
C		DI: diameter of polygon in inches.
C		BW: polygon border width in inches.
C		XP: x-coordinate of polygon center in inches.
C		YP: y-coordinate of polygon center in inches.
C		RA: rotation angle in degrees.
C
C		Subroutine call is "IFPOLY".
C
C %018	OBLI: R1,R2,BW,XP,YP,RA ...... (A4,X,6F8.3)
C
C		Oblique generation instruction, where
C
C		R1: radius of oblique in x-axis in inches.
C		R2: radius of oblique in y-axis in inches.
C		BW: oblique border width in inches.
C		XP: x-coordinate of oblique center in inches.
C		YP: y-coordinate of oblique center in inches.
C		RA: rotation angle in degrees.
C
C		Subroutine call is "IFOBLI".
C
C %019	BOXS: BL,BH,BW,XP,YP,RA ...... (A4,X,6F8.3)
C
C		Box generation instruction, where
C
C		BL: box length in inches in x-axis.
C		BH: box height in inches in y-axis.
C		BW: box border width in inches.
C		XP: center of box in inches (X).
C		YP: center of box in inches (Y).
C		RA: rotation angle of box in degrees.
C
C		Boxs are round-cornered.
C		Subroutine call is "IFBOXS".
C
C %020	CIRC: R1,XP,YP,CA ...... (A4,X,4F8.3)
C
C		Circle generation instruction, where
C
C		R1: radius of circle in inches.
C		XP: x-coordinate of arc center in inches.
C		YP: x-coordinate of arc center in inches.
C		CA: chord angle in degrees [10.0].
C
C		Subroutine call is "IFCIRC".
C %021	ELLP: RX,RY,XP,YP,CA ...... (A4,X,5F8.3)
C
C		Ellipse generation instruction, where
C
C		RX: x-radius of ellipse in inches.
C		RY: y-radius of ellipse in inches.
C		XP: x-coordinate of arc center in inches.
C		YP: x-coordinate of arc center in inches.
C		CA: chord angle in degrees [10.0].
C
C		Subroutine call is "IFELLP".
C================================================================

     	PARAMETER	(LIN= 51, LOUT= 52)
     	LOGICAL		INIT, FEED, TOPP
     	BYTE		ESC
     	CHARACTER	KEYW*4, TEXT*132, BLANK*1, STRING*80
     	DIMENSION	XP(20), YP(20), IP(20)
     	EQUIVALENCE	(KEYW(1:1),TEXT(1:1))
     	DATA BLANK	/ ' ' /
     	DATA ESC	/ 27 /
C
C  GET THE INPUT AND OUTPUT FILES FIRST...
C
  1	READ(5,1000,END=999) TEXT
     	IF( TEXT.EQ.' ' ) GOTO 1
     	OPEN(UNIT=LIN,FILE=TEXT,STATUS='OLD',FORM='FORMATTED')

  3	READ(5,1000,END=999) TEXT
     	IF( TEXT.EQ.' ' ) GOTO 3
     	TOPP = .FALSE.
     	IF( TEXT(1:3).EQ.'PP:' ) THEN
     	    TOPP = .TRUE.
     	    TEXT = 'TT:'
     	ENDIF
     	IF( TEXT(1:3).EQ.'TT:' ) THEN
     	    OPEN( UNIT=LOUT, FILE='SYS$OUTPUT', STATUS='NEW',
     +      FORM='FORMATTED', CARRIAGECONTROL='NONE' )
     	    IF( TOPP ) WRITE(LOUT,1234) ESC
 1234	    FORMAT(A1,'[5i')		!PRINTER PORT ON
     	ELSE
     	    OPEN( UNIT=LOUT, FILE=TEXT, STATUS='NEW',
     +      FORM='FORMATTED', CARRIAGECONTROL='LIST' )
     	ENDIF
C
C  READ THE "INIT:" LINE FROM SYS$INPUT:
C
     	INIT = .FALSE.
     	READ(5,1000,END=999) TEXT
     	IF( TEXT.NE.BLANK ) GOTO 222
C
C  START READING THE INPUT FILE...
C
 111	READ(LIN,1000,ERR=1111,END=888) TEXT
 1000	FORMAT(A)
     	IF( TEXT.EQ.BLANK ) GOTO 111

 222	IF( KEYW .EQ. 'INIT' ) THEN	!INITIALIZATION
     	    IF( INIT ) GOTO 1111	!MULTIPLE INITIALIZATION
     	    READ(TEXT,1001,ERR=1111) (XP(I), I=1, 16)
     	    INIT = .TRUE.
     	    FEED = .FALSE.
     	    CALL IFINIT( LOUT, 16, XP )
     	    GOTO 111
     	ENDIF
 1001	FORMAT(5X,16F7.2)

     	IF( .NOT.INIT ) GOTO 1111	!NOT INITIALIZED YET

     	IF( KEYW .EQ. 'FEED' ) THEN	!PAGE FEED
     	    IF( FEED ) GOTO 1111	!MULTIPLE PAGE FEED
     	    FEED = .TRUE.
     	    INIT = .FALSE.
     	    READ(TEXT,1002,ERR=1111) IFEED
     	    CALL IFFEED( IFEED )
     	    GOTO 111
     	ENDIF
 1002	FORMAT(5X,I3)

     	IF( KEYW .EQ. 'PLOT' ) THEN	!PLOT ACTION
     	    READ(TEXT,1003,ERR=1111) (XP(I),YP(I),IP(I),I=1,9)
     	    DO I=1, 9
     	       IF( IP(I).EQ.0 ) GOTO 111
     	       CALL IFPLOT( XP(I), YP(I), IP(I) )
     	    ENDDO
     	    GOTO 111
     	ENDIF
 1003	FORMAT(5X,9(2F6.3,I2))

     	IF( KEYW .EQ. 'TEXT' ) THEN	!TEXT DRAWING ACTION
     	    READ(TEXT,1004,ERR=1111) IP(1),(XP(I),I=1,5),STRING
     	    CALL IFTEXT( IP(1), STRING, 5, XP )
     	    GOTO 111
     	ENDIF
 1004	FORMAT(5X,I3,5F8.3,X,A80)

     	IF( KEYW .EQ. 'BOXS' ) THEN	!BOX DRAWING ACTION
     	    READ(TEXT,1005,ERR=1111) (XP(I),I=1,6)
     	    CALL IFBOXS( 6, XP )
     	    GOTO 111
     	ENDIF
 1005	FORMAT(5X,6F8.3)

     	IF( KEYW .EQ. 'MARK' ) THEN	!SYMBOL DRAWING ACTION
     	    READ(TEXT,1006,ERR=1111) IP(1),(XP(I),I=1,4)
     	    CALL IFMARK( IP(1), 4, XP )
     	    GOTO 111
     	ENDIF
 1006	FORMAT(5X,I3,4F8.3)

     	IF( KEYW .EQ. 'BARS' ) THEN	!BAR DRAWING ACTION
     	    READ(TEXT,1007,ERR=1111) (XP(I),I=1,6)
     	    CALL IFBARS( 6, XP )
     	    GOTO 111
     	ENDIF
 1007	FORMAT(5X,6F8.3)

     	IF( KEYW .EQ. 'ARCS' ) THEN	!ARC DRAWING ACTION
     	    READ(TEXT,1008,ERR=1111) (XP(I),I=1,9)
     	    CALL IFARCS( 9, XP )
     	    GOTO 111
     	ENDIF
 1008	FORMAT(5X,9F8.3)

     	IF( KEYW .EQ. 'ARRH' ) THEN	!ARROWHEAD DRAWING ACTION
     	    READ(TEXT,1009,ERR=1111) IP(1),(XP(I),I=1,6)
     	    CALL IFARRH( IP(1), 6, XP )
     	    GOTO 111
     	ENDIF
 1009	FORMAT(5X,I3,6F8.3)

     	IF( KEYW .EQ. 'POLY' ) THEN	!POLYGON DRAWING ACTION
     	    READ(TEXT,1010,ERR=1111) IP(1),(XP(I),I=1,5)
     	    CALL IFPOLY( IP(1), 5, XP )
     	    GOTO 111
     	ENDIF
 1010	FORMAT(5X,I3,5F8.3)

     	IF( KEYW .EQ. 'OBLI' ) THEN	!OBLIQUE DRAWING ACTION
     	    READ(TEXT,1011,ERR=1111) (XP(I),I=1,6)
     	    CALL IFOBLI( 6, XP )
     	    GOTO 111
     	ENDIF
 1011	FORMAT(5X,6F8.3)

     	IF( KEYW .EQ. 'SCAL' ) THEN	!GRAPH OVERALL SCALE FACTORS
     	    READ(TEXT,1012,ERR=1111) XP(1), XP(2)
     	    CALL IFSCAL( XP(1), XP(2) )
     	    GOTO 111
     	ENDIF
 1012	FORMAT(5X,2F8.3)

     	IF( KEYW .EQ. 'ROTA' ) THEN	!GRAPH ROTATION
     	    READ(TEXT,1013,ERR=1111) XP(1), XP(2)
     	    CALL IFROTA( XP(1), XP(2) )
     	    GOTO 111
     	ENDIF
 1013	FORMAT(5X,2F8.3)

     	IF( KEYW .EQ. 'SPEN' ) THEN	!ACTIVE PEN/COLOR
     	    READ(TEXT,1014,ERR=1111) IP(1)
     	    CALL IFSPEN( IP(1) )
     	    GOTO 111
     	ENDIF
 1014	FORMAT(5X,I3)

     	IF( KEYW .EQ. 'FONT' ) THEN	!ACTIVE FONT
     	    READ(TEXT,1015,ERR=1111) IP(1)
     	    CALL IFFONT( IP(1) )
     	    GOTO 111
     	ENDIF
 1015	FORMAT(5X,I3)

     	IF( KEYW .EQ. 'STYL' ) THEN	!ACTIVE PLOTTING STYLUS
     	    READ(TEXT,1016,ERR=1111) IP(1), IP(2)
     	    CALL IFSTYL( IP(1), IP(2) )
     	    GOTO 111
     	ENDIF
 1016	FORMAT(5X,2I3)

     	IF( KEYW .EQ. 'FILL' ) THEN	!POLYGON FILL ON/OFF
     	    READ(TEXT,1017,ERR=1111) IP(1)
     	    CALL IFFILL( IP(1) )
     	    GOTO 111
     	ENDIF
 1017	FORMAT(5X,I3)

     	IF( KEYW .EQ. 'STAR' ) THEN	!PLOT SESSION INITILIZATION
     	    READ(TEXT,1018,ERR=1111) XP(1),YP(1)
     	    CALL IFINIT_PLOT( XP(1), YP(1) )
     	    GOTO 111
     	ENDIF
 1018	FORMAT(5X,2F8.3)

     	IF( KEYW .EQ. 'CIRC' ) THEN	!CIRCLE DRAWING ACTION
     	    READ(TEXT,1019,ERR=1111) (XP(I),I=1,4)
     	    CALL IFCIRC( 4, XP )
     	    GOTO 111
     	ENDIF
 1019	FORMAT(5X,4F8.3)

     	IF( KEYW .EQ. 'ELLP' ) THEN	!ELLIPSE DRAWING ACTION
     	    READ(TEXT,1020,ERR=1111) (XP(I),I=1,5)
     	    CALL IFELLP( 5, XP )
     	    GOTO 111
     	ENDIF
 1020	FORMAT(5X,5F8.3)

C
C  UNRECOGNIZED KEYWORD IS IGNORED...
C
     	WRITE(6,2222) TEXT
 2222	FORMAT(X'??? ',A75)
     	GOTO 111
C
C  FATAL ERROR INPUT FORMAT...
C
 1111	WRITE(6,1112) TEXT
 1112	FORMAT(X'??? ',A75)
     	GOTO 999
C
C  FEED THE PLOT PAGE...
C
 888	IF( .NOT.FEED ) CALL IFFEED(1)
 999	IF( TOPP ) WRITE(LOUT,4321) ESC
 4321	FORMAT(A1,'[4i')		!PRINTER PORT OFF
     	CLOSE( UNIT=LIN, STATUS='DELETE' )
     	CLOSE( UNIT=LOUT )
     	CALL EXIT
     	END
