      integer*2 function vopnwk()

c     Purpose:  Files to perform graphics using LLNL Diglib routine
c               N.B. Coloring problems may occur for text.

      implicit integer*2 (a-z)

      integer         jfill,jplot
      logical                     lfil
      common /instl2/ jfill,jplot,lfil

      common /vgraph/ icoll,icolt,icolf,ixln,iyln,idxl,idyl,itxl,ityl

c     Open workstation

      call setup()
      if(jfill.eq.2) then
        call mode(16)
        ixln = 639
        iyln = 349
        idxl = 51
        idyl = 64
      else
        call mode( 6)
        ixln = 639
        iyln = 199
        idxl = 51
        idyl = 112
      endif
      call rowcol(0,0)
      itxl = 400
      ityl = 880
      vopnwk = 0
      end

      integer*2 function vclrwk()

      implicit integer*2 (a-z)

c     Clear workstation

      call clr()
      call rowcol(0,0)
      vclrwk = 0
      end

      integer*2 function vclswk()

      implicit integer*2 (a-z)

c     Close workstation

      call clr()
      call mode(7)
      call rowcol(0,0)
      vclswk = 0
      end

      integer*2 function vgtxts(ixi,iyi,nc,cstr)

      implicit integer*2 (a-z)

      character*1 cstr(nc)
      common /vgraph/ icoll,icolt,icolf,ixln,iyln,idxl,idyl,itxl,ityl

c     Position cursor to (ixi,iyi) then write cstr(nc)

      ixp = ixi/itxl
      iyp = iyi/ityl
      call rowcol(24-iyp,ixp)
      call coatr(cstr(1),icolt)
      do 100 i = 1,nc
        call co(cstr(i))
100   continue
      vgtxts = 0

      end

      integer*2 function vrqstr(len,echoh,ixy,cstr)

      implicit  integer*2 (a-z)
      integer   len,echoh
      character cstr(len)*1
      integer*2 ixy(2)
      common /vgraph/ icoll,icolt,icolf,ixln,iyln,idxl,idyl,itxl,ityl

c.... input string ; max length is len
c.... echoh = echo mode - display if 1 else nodisplay if 0
c.... ixy is location of echo; max length is len

      ixp = ixy(1)/itxl
      iyp = ixy(2)/ityl
      call rowcol(24-iyp,ixp)
      do 100 i = 1,len
        cstr(i) = ' '
100   continue
      i = 1
102   continue
        ichr = ci()
        if(ichr.eq. 8) then
          i = max(1,i - 1)
          if(echoh.eq.1) then 
            cstr(i) = ' '
            call rowcol(24-iyp,ixp-1+i)
            call co(cstr(i))
            call rowcol(24-iyp,ixp-1+i)
          endif
        elseif(ichr.eq.13) then
          return
        else
          cstr(i) = char(ichr)
          if(echoh.eq.1) call co(cstr(i))
          i = i + 1
        endif
      if(i.le.len) go to 102
      vrqstr = 0
      end

      integer*2 function vslcol(it)

      implicit integer*2 (a-z)
      common /vgraph/ icoll,icolt,icolf,ixln,iyln,idxl,idyl,itxl,ityl

c     Set line color

      icoll = vipal(it)
      vslcol = 0
      end

      integer*2 function vpline(npt,pxy)

      implicit integer*2 (a-z)
      integer*2 pxy(2,npt)
      common /vgraph/ icoll,icolt,icolf,ixln,iyln,idxl,idyl,itxl,ityl

c     Set line type

      if(npt.lt.2) return
      do 100 n = 2,npt
        call odot(pxy(1,n-1),pxy(2,n-1),pxy(1,n),pxy(2,n),icoll)
100   continue
      vpline = 0
      end

      integer*2 function vencur()

      implicit integer*2 (a-z)

c     Set line type

      call mode(7)
      vencur = 0
      end

      integer*2 function vipal(icol)

      implicit integer*2 (a-z)

      integer         jfill,jplot
      logical                     lfil
      common /instl2/ jfill,jplot,lfil
      dimension ipal(7)

      data ipal/ 15, 4, 2, 1, 14, 3, 5/

      if(icol.gt.0 .and. icol.le.7 ) then
        vipal = ipal(icol)
        if(jfill.lt.2) vipal = min(vipal,1)
      else
        vipal = 0
      endif
      end

      subroutine odot(ix1,iy1,ix2,iy2,icol)

      implicit integer*2 (a-z)

      common /vgraph/ icoll,icolt,icolf,ixln,iyln,idxl,idyl,itxl,ityl

c       Draw a line

        ixposn = ix1/idxl + 1
        iyposn = iy1/idyl + 1
        ix     = ix2/idxl + 1
        iy     = iy2/idyl + 1

        iic   = icol
        idx   = ix-ixposn
        iadx  = abs(idx)
        idy   = iy-iyposn
        iady  = abs(idy)
        iadx2 = iadx + iadx
        iady2 = iady + iady
        if (iadx .eq. 0) then
          iix = ixposn-1
          iiy = min(iyposn,iy)
          do 410 i = iady+1,1,-1
            call wdot(iix,iyln-iiy,iic)
            iiy = iiy+1
410       continue
        elseif (iady .eq. 0) then
          iix = min(ixposn,ix)
          iiy = iyln-iyposn
          do 430 i = iadx+1,1,-1
            call wdot(iix-1,iiy,iic)
            iix = iix+1
430       continue
        elseif (iadx .lt. iady) then
          id  = iadx2-iady
          id1 = iadx2
          id2 = iadx2-iady2
          if (iyposn .lt. iy) then
            iix = ixposn
            iiy = iyposn
          else
            iix = ix
            iiy = iy
          endif
          if (idx*idy .ge. 0) then
            istep = 1
          else
            istep = -1
          endif
          call wdot(iix-1,iyln-iiy,iic)
          do 440 i = iady,1,-1
            iiy = iiy+1
            if (id .lt. 0) then
              id = id1+id
            else
              iix = istep+iix
              id = id2+id
            endif
            call wdot(iix-1,iyln-iiy,iic)
440       continue
        else
          id  = iady2-iadx
          id1 = iady2
          id2 = iady2-iadx2
          if (ixposn .lt. ix) then
            iix = ixposn
            iiy = iyposn
          else
            iix = ix
            iiy = iy
          endif
          if (idx*idy .ge. 0) then
            istep = 1
          else
            istep = -1
          endif
          call wdot(iix-1,iyln-iiy,iic)
          do 450 i = iadx,1,-1
            iix = iix+1
            if (id .lt. 0) then
              id = id1+id
            else
              iiy = istep+iiy
              id = id2+id
            endif
            call wdot(iix-1,iyln-iiy,iic)
450       continue
        endif

        end

      subroutine dplot(x,y,ipen)

c     Purpose: Plot line routine

c     Inputs:
c        x         - X-normalized coordinate to plot
c        y         - Y-normalized coordinate to plot
c        ipen      - Pen action: = 2 draw; = 3 move

c     Outputs:
c        none

      implicit   none

      integer*2  status,vpline
      integer    ipen
      real*8     x,y

      integer*2       ixy
      common /pdata2/ ixy(4)

c     Pen command motions  (ipen = 2, pendown)

      ixy(3) = 22000*x
      ixy(4) = 22000*y
      if(ipen.eq.2) then
        status = vpline(2,ixy)
      endif
      ixy(1) = ixy(3)
      ixy(2) = ixy(4)

      end
