      Subroutine Movleg
c ***********************************************************************
c *                                                                     *
c *        Subroutine Movleg  -  To move and change the plot legend     *
c *        on the screen.                                               *
c *                                                                     *
c *            Programmed by Steven C. Fisher, DTRC Code 1522           *
c *                                                                     *
c ***********************************************************************
c
      Common/Legmov/Xorig,Yorig,Xlegln,Ylegln,Lesize,Legcnr,Leglin,
     $              Gblspc
c
 10   Continue
c
      Write(7,100) 27,27
100   Format(1X,A1,'[HLEGEND: Select (M)ove, (T)ext size, (V)ertical',
     $             ' spacing, or (S)top ',A1,'[K',$)
c
      Call Instrg('MmTtVvSs',8,Ido)
      Ido = (Ido+1)/2
c
      If (Ido .EQ. 1) Then
         Write(7,150) 27,27
150      Format(1X,A1,'[HPut crosshair on the legend corner to move',
     $            ' using. ',A1,'[K',$)
         Call Cross('Ss ',3,Xpos,Ypos,Nflag)
         If (Nflag .EQ. 1 .OR. Nflag .EQ. 2) Go To 10
c
         Call Nrleg(Xpos,Ypos,Nc,Xorig,Yorig,Xlegln,Ylegln)
c
         Write(7,200) 27,7,27
200      Format(1X,A1,'[HNow, move the cursor to the place to move',
     $            ' the legend to ',2A1,'[K',$)
         Call Cross('Ss ',3,Xpos,Ypos,Nflag)
         If (Nflag .EQ. 1 .OR. Nflag .EQ. 2) Go To 10
c
c              If the point is close to the axes, move it
c              over to the axes
c
         Call Gtwind(Xl,Xr,Yb,Yt)
         If (Abs((Xpos-Xl)/(Xr-Xl)) .LT. 0.010) Then
            Xpos = Xl
         End If
         If (Abs((Xpos-Xr)/(Xr-Xl)) .LT. 0.010) Then
            Xpos = Xr
         End If
         If (Abs((Ypos-Yb)/(Yt-Yb)) .LT. 0.010) Then
            Ypos = Yb
         End If
         If (Abs((Ypos-Yt)/(Yt-Yb)) .LT. 0.010) Then
            Ypos = Yt
         End If
c
         Call PlDlSt
         Call Pltleg
         Call PlDlEn
c
         Call Newleg(Xpos,Ypos,Nc,Xorig,Yorig,Xlegln,Ylegln)
         Call Plton
         Call Pltleg
         Call Boxax
         Call Pltoff
         Legcnr = Nc
c
      Else If (Ido .EQ. 2) Then
c
         Write(7,300) 27,27
300      Format(1X,A1,'[HEnter the new legend text size  ',A1,'[K',$)
         Call Inchek(1,10,Isize)
         If (Isize .EQ. Lesize) Go To 10
c
c                 Scale the legend size
c
         If (Isize .EQ. 1) Then
            Size = 1.7
         Else If (Isize .EQ. 2) Then
            Size = 2.3
         Else
            Size = Isize
         End If
c
         If (Lesize .EQ. 1) Then
            Sizel = 1.7
         Else If (Lesize .EQ. 2) Then
            Sizel = 2.3
         Else
            Sizel = Lesize
         End If
c
         Call PlDlSt
         Call Pltleg
         Call PlDlEn
c
         Ratio  = Size / Sizel
         Lesize = Isize
         Call Sizleg(Xorig,Yorig,Legcnr,Xlegln,Ylegln,Ratio)
         Call Plton
         Call Pltleg
         Call Boxax
         Call Pltoff
c
      Else If (Ido .EQ. 3) Then
 30      Continue
         Write(7,350) 27,27
350      Format(1X,A1,'[HEnter the new vertical spacing factor ',
     $                ' (0.3 to 2.0)  ',A1,'[K',$)
         Call Rnum(Gb)
         Gb = Amax1(0.3,Amin1(2.0,Gb))
         If (Gb .EQ. Gblspc) Go To 10
c
         Call PlDlSt
         Call Pltleg
         Call PlDlEn
c
         Ratio  = (1.5+Leglin*(1.0+Gb))/(1.5+Leglin*(1.0+Gblspc))
         Call Vertlg(Yorig,Legcnr,Ylegln,Ratio)
         Gblspc = Gb
c
         Call Plton
         Call Pltleg
         Call Boxax
         Call Pltoff
c
      Else
         Return
      End If
c
      Go To 10
c
      End
      Subroutine Pltleg
c ***********************************************************************
c *                                                                     *
c *        Subroutine Pltleg  -  To plot the legend border on the       *
c *        screen, including a label stating it is the legend           *
c *                                                                     *
c *            Programmed by Steven C. Fisher, DTRC Code 1522           *
c *                                                                     *
c ***********************************************************************
c
      Dimension X(5),Y(5)
      Common/Legmov/Xorig,Yorig,Xlegln,Ylegln,Lesize,Legcnr,Leglin,
     $              Gblspc
      Integer Spchar,Atxclr,Xtop
      Common/Ptype/Idev,Xtop,Spchar,Chscal,Chsc1
c
      X(1) = Xorig
      Y(1) = Yorig
      X(2) = Xorig + Xlegln
      Y(2) = Yorig
      X(3) = X(2)
      Y(3) = Yorig + Ylegln
      X(4) = Xorig
      Y(4) = Y(3)
      X(5) = Xorig
      Y(5) = Yorig
c
         If (Lesize .EQ. 1) Then
            Sizel = 1.7
         Else If (Lesize .EQ. 2) Then
            Sizel = 2.3
         Else
            Sizel = Lesize
         End If
c
      Call Wccurv(X,Y,5)
      Call Stjust(5)
      Call Movawc(Xorig+Xlegln/2.0,Yorig+Ylegln/2.0)
      Call Stccsz(Sizel*0.03*Chscal,Sizel*0.042*Chscal)
      Call Grtxcp(99,'@@@1(LEGEND)\')
c
      Return
      End
      Subroutine Boxax
c ***********************************************************************
c *                                                                     *
c *        Subroutine Boxax  -  To redraw the box around the axes,      *
c *        which may become erased when altering the legend or text     *
c *        blocks.                                                      *
c *                                                                     *
c *            Programmed by Steven C. Fisher, DTRC Code 1522           *
c *                                                                     *
c ***********************************************************************
c
      Dimension Xmin(2),Ymin(2),Xmax(2),Ymax(2),Xinc(2),Yinc(2)
      Integer Xnumbr,Ynumbr,Axchst,Axtypx,Axtypy,Axcolr,Ticdir
      Byte Xaxis(2,80),Yaxis(2,80)
c
      Byte Titl(80),Char
c
      Integer Atxclr,Spchar,Xtop
c
      Common/Ptype/Idev,Xtop,Spchar,Chscal
      Common/Labls/Nold,Lachst,Lacolr,Nleg,Lechst,Lecolr,Legtit,Labcrd,
     $ Iprtot,Irott
      Common/Axis/Xmin,Xmax,Ymin,Ymax,Xinc,Yinc,Xlen,Ylen,Xnumbr,
     $ Ynumbr,Xaxis,Yaxis,Axthik,Axchst,Axtypx,Axtypy,Axcolr,Textsz,
     $ Ticdir,Atxclr
c
      If (Labcrd .EQ. 0) Then
c
c         Set up local coordinate system
c
         Call Plwin(Xmin(1),Xmax(1),Ymin(1),Ymax(1),Xlen,Ylen)
         Call Wframe
         Call Plcord(Xmin(1),Xmax(1),Ymin(1),Ymax(1),Xlen,Ylen)
c
      Else
c
c         Set up global coordinate system
c
         Call Plwin(0.0,1.0,0.0,1.0,Xlen,Ylen)
         Call Wframe
         Call Plcord(0.0,1.0,0.0,1.0,Xlen,Ylen)
c
      End If
c
      Return
      End
      Subroutine Mvtxbl
c ***********************************************************************
c *                                                                     *
c *        Subroutine Mvtxbl  -  To move and change the text blocks     *
c *        on the screen.                                               *
c *                                                                     *
c *            Programmed by Steven C. Fisher, DTRC Code 1522           *
c *                                                                     *
c ***********************************************************************
c
      Common/Textbl/Ntxbl
      Common/Txplot/Xtxorg(10),Ytxorg(10),Xtlen(10),Ytlen(10),
     $              Loctx(10),Txszrt(10),Txspac(10),Txlen(10)
c
      If (Ntxbl .EQ. 0) Return
 10   Continue
c
      Write(7,100) 27,27
100   Format(1X,A1,'[HTEXT BLOCKS: Select (M)ove, (G)lobal spacing',
     $              ' factor, or (S)top ',A1,
     $          '[K',$)
c
      Call Instrg('MmGgSs',6,Ido)
      Ido = (Ido+1)/2
c
      If (Ido .EQ. 1) Then
         Write(7,150) 27,27
150      Format(1X,A1,'[HPut crosshair on the text block corner to move',
     $            ' using. ',A1,'[K',$)
         Call Cross('Ss ',3,Xpos,Ypos,Nflag)
         If (Nflag .EQ. 1 .OR. Nflag .EQ. 2) Go To 10
c
         Call Neartb(Xpos,Ypos,N)
         Call Nrleg(Xpos,Ypos,Nc,Xtxorg(N),Ytxorg(N),
     $                    Xtlen(N),Ytlen(N))
c
         Write(7,200) 27,7,27
200      Format(1X,A1,'[HNow, move the cursor to the place to move',
     $            ' the text block to ',2A1,'[K',$)
         Call Cross('Ss ',3,Xpos,Ypos,Nflag)
         If (Nflag .EQ. 1 .OR. Nflag .EQ. 2) Go To 10
c
c              If the point is close to the axes, move it
c              over to the axes
c
         Call Gtwind(Xl,Xr,Yb,Yt)
         If (Abs((Xpos-Xl)/(Xr-Xl)) .LT. 0.01) Then
            Xpos = Xl
         End If
         If (Abs((Xpos-Xr)/(Xr-Xl)) .LT. 0.01) Then
            Xpos = Xr
         End If
         If (Abs((Ypos-Yb)/(Yt-Yb)) .LT. 0.01) Then
            Ypos = Yb
         End If
         If (Abs((Ypos-Yt)/(Yt-Yb)) .LT. 0.01) Then
            Ypos = Yt
         End If
c
         Call PlDlSt
         Call Pltext(N)
         Call PlDlEn
c
         Call Newleg(Xpos,Ypos,Nc,Xtxorg(N),Ytxorg(N),
     $                   Xtlen(N),Ytlen(N))
         Call Plton
         Call Pltext(N)
         Call Boxax
         Call Pltoff
         Loctx(N) = Nc
c
      Else If (Ido .EQ. 2) Then
c
c                 Select the text block to change if more than one
c
         If (Ntxbl .GT. 1) Then
            Write(7,250) 27,27
250         Format(1X,A1,'[HPut crosshair on the text block to change',
     $                A1,'[K',$)
            Call Cross('Ss ',3,Xpos,Ypos,Nflag)
            If (Nflag .EQ. 1 .OR. Nflag .EQ. 2) Go To 10
c
            Call Neartb(Xpos,Ypos,N)
         Else
            N = 1
         End If
c
         Write(7,300) 27,27
300      Format(1X,A1,'[HEnter the global spacing factor value  ',A1,
     $            '[K',$)
         Call Rnum(Gb)
         Gb = Amax1(0.0,Gb)
         If (Gb .EQ. Txspac(N)) Go To 10
c
c                  Erase the current text block
c
         Call PlDlSt
         Call Pltext(N)
         Call PlDlEn
c
c                  Compute the new text block
c
         Y         = Gb/Txspac(N) * (Ytlen(N)-Txlen(N)) + Txlen(N)
         Ratio     = Y / Ytlen(N)
         Txspac(N) = Gb
         Call Vertlg(Ytxorg(N),Loctx(N),Ytlen(N),Ratio)
c
c                   Draw the new text block
c
         Call Plton
         Call Pltext(N)
         Call Boxax
         Call Pltoff
      Else
         Return
      End If
c
      Go To 10
c
      End
      Subroutine Pltext(N)
c ***********************************************************************
c *                                                                     *
c *        Subroutine Pltext  -  To plot a text block on the screen     *
c *        on the screen.                                               *
c *                                                                     *
c *            Programmed by Steven C. Fisher, DTRC Code 1522           *
c *                                                                     *
c ***********************************************************************
c
      Dimension X(5),Y(5)
      Common/Txplot/Xtxorg(10),Ytxorg(10),Xtlen(10),Ytlen(10),
     $              Loctx(10),Txszrt(10),Txspac(10),Txlen(10)
      Integer Spchar,Atxclr,Xtop
      Common/Ptype/Idev,Xtop,Spchar,Chscal,Chsc1
      Character Strinc*20
      Byte Strinb(20)
      Equivalence (Strinc,Strinb)
c
      X(1) = Xtxorg(N)
      Y(1) = Ytxorg(N)
      X(2) = Xtxorg(N) + Xtlen(N)
      Y(2) = Ytxorg(N)
      X(3) = X(2)
      Y(3) = Ytxorg(N) + Ytlen(N)
      X(4) = Xtxorg(N)
      Y(4) = Y(3)
      X(5) = Xtxorg(N)
      Y(5) = Ytxorg(N)
c
      Call Wccurv(X,Y,5)
      Call Stjust(5)
      Call Movawc(Xtxorg(N)+Xtlen(N)/2.0,Ytxorg(N)+Ytlen(N)/2.0)
      Call Stccsz(Txszrt(N)*0.3*Chscal,Txszrt(N)*0.42*Chscal)
      Encode(19,100,Strinc) N
100   Format('@@@1(TEXT BLOCK',I3,')')
      Call Grtxcp(19,Strinb)
c
      Return
      End
