	subroutine plot (x, y, ipen)
	real             x, y
	integer                ipen
C
C  Plotter driver conforming to:
C    "Programming CalComp Electromechanical Plotters", CalComp, January 1976
C    Output for PostScript printers like Apple LaserWriter Plus
C
C  Rex Sanders, USGS, 2/87
C
C  Where:
C    x,y = coordinates, in inches from the current origin, of the position
C          to which the pen is to be moved
C
C    ipen = pen control, origin definition, and plot termiination such that:
C      if ipen = 1, move with pen in present condition
C      if ipen = 2, move with pen down
C      if ipen = 3, move with pen up
C      if ipen = -1, move with no pen change, reset origin to terminal position
C      if ipen = -2, move with pen down, reset origin to terminal position
C      if ipen = -3, move with pen up, reset origin to terminal position
C      if ipen = 999, move with pen up, terminate plot, close plot file
C      if ipen = anything else, no action is taken
C

	common /cqpbnf/ xold, yold, fac, ires
	save   /cqpbnf/
	real            xold, yold, fac
	integer                          ires

	integer locpen
	logical penup
	save    penup
	data	penup /.true./

	locpen = abs (ipen)

C
C   Check pen for proper values
C
	if (locpen .ne. 1 .and. locpen .ne. 2 .and. locpen .ne. 3 .and.
&	      ipen .ne. 999) return

C
C   Reset locpen to current pen status
C
	if (locpen .eq. 1) then
	    if (penup) then
		locpen = 3
	    else
		locpen = 2
	    endif
	endif

C
C   Set up for move or draw
C     Output "x y"
C
	call pliout (nint (x * fac * ires))
	call plcout (32)
	call pliout (nint (y * fac * ires))

C
C   Pen down - draw
C
	if (locpen .eq. 2) then
	    call plsout (" D\n")
	    penup = .false.

C
C   Pen up - move
C
	else if (locpen .eq. 3 .or. locpen .eq. 999) then
	    call plsout (" M\n")
	    penup = .true.
	endif

	if (ipen .ge. 0) then
	    xold = x
	    yold = y
	else
C
C	Set new origin
C
	    call plsout ("O\n")
	    xold = 0.0
	    yold = 0.0
	endif

C
C   Close and clean up plot file
C
	if (ipen .eq. 999) then
	    call plsout ("showpage\n")
	    call pldone
	endif

	return
	end
