      subroutine rubber_box(coordxl,coordyl,coordxh,coordyh)
c
c This routine will draw a rubber banded box and report back
c the significant corners.  Much toil went into writing this
c short, but sweet routine.
c
c James Blake
c @(#)rubber_box.f	1.1  4/3/89 
c
      integer x,y,xlist(10),ylist(10),valid,choice
      integer ix(5), iy(5) 
      character*80 string
c
c Initialize the graphics input devices and numbers.
c
      x = 16384
      y = 16384
      call cfinitlid(0,1,x,y,xlist,ylist,n,val,choice,
     $               string,segid,pickid)
c
c Associate mouse buttons to the event.
c
      call cfassoc(2,0,1)
      call cftrackon(0,1,1,0,0,10000,10000,x,y,xlist,ylist,n,
     $               val,choice,string,segid,pickid)
c
c Get the first point on the box
c
      call cfreqinp(0,1,-1,valid,itrig,x,y,xlist,ylist,n,
     $              val,choice,string,segid,itrig,pickid)
c     
c Enable tracing of the mouse position.
c
      call cfassoc(5,0,1)
c
c set a good color and XOR drawing mode.
c
      call newpen(3)
      call cfsgldrawmode(4)
c
      do icount = 1, 5
         ix(icount) = x
         iy(icount) = y 
      enddo
      valid = 0
      itrig = 0
c
c Loop while the user is moving the mouse.
c
      do while (valid .eq. 0 .and. itrig .ne. 2)
         call cfreqinp(0,1,-1,valid,itrig,x,y,xlist,ylist,n,
     $                 val,choice,string,segid,itrig,pickid)
c
         call cfpolyline(ix,iy,5)
         ix(2) = x 
         ix(3) = x 
         iy(3) = y
         iy(4) = y
         call cfpolyline(ix,iy,5)
      enddo
c
c Dissociate the buttons and release the device.
c
      call cfpolyline(ix,iy,5)
      call cfsgldrawmode(0)
      call cfdissoc(2,0,1)
      call cfdissoc(5,0,1)
      call cfrelidev(0,1)
      tcoordxl = page_x(ix(1))
      tcoordyl = page_y(iy(1))
      tcoordxh = page_x(ix(3))
      tcoordyh = page_y(iy(3))
      coordxl = min(tcoordxl,tcoordxh)
      coordyl = min(tcoordyl,tcoordyh)
      coordxh = max(tcoordxl,tcoordxh)
      coordyh = max(tcoordyl,tcoordyh)
      call newpen(1)
      return
      end
