      Subroutine Sizplt
c
c ***********************************************************************
c *                                                                     *
c *         Subroutine 	Sizplt - To size the plot maximum and           *
c *         minimum extents, to be used by PLOTFL to size and orient    *
c *         the plot so that it will fit on the plot area.              *
c *                                                                     *
c *          Programmed by Steven C. Fisher, DTNSRDC Code 1522          *
c *                                                                     *
c ***********************************************************************
c
      Include 'Cmain'
      Include 'Cplot'
      Include 'Caxis'
      Include 'Clabls'
      Include 'Ctxblk'
      Include 'Clegnd'
      Include 'Cdefl'
      Include 'Cplsiz'
c
c            Compute the size (height and width) of the plot
c
      Ylmin = - 4.0 * 0.042 * Textsz - Axthik/2.0
      If (Ticdir .EQ. 2) Ylmin = Ylmin - 0.6 * 0.042 * Textsz
      If (Ynumbr .EQ. 2) Then
         Ylmax = Ylen  + 4.2 * 0.042 * Textsz + Axthik/2.0
         If (Ticdir .EQ. 2) Ylmax = Ylmax + 0.6 * 0.042 * Textsz
      Else
         Ylmax = Ylen  + 0.042 * Textsz * 0.8 + Axthik/2.0
      End If
      Xlmin = 0.0
      Xlmax = Xlen
c
c           Add in the height and width due to the labels
c
      Do 10 I=1,Nlab
         If (Sizlab(I) .EQ. 0) Go To 10
         If (Labcrd .EQ. 0) Then
            Yo = (Ylabel(I) - Ymin(1)) * Ylen / (Ymax(1)-Ymin(1))
            Xo = (Xlabel(I) - Xmin(1)) * Xlen / (Xmax(1)-Xmin(1))
          Else
            Yo = Ylabel(I) * Ylen
            Xo = Xlabel(I) * Xlen
         End If
         Call Name(Titl,I,Label,Llabel)
         Sizes = Sizlab(I)
         Call Strlen(Titl,Llabel(I),Lachst,Sizlab(I),Rlenth)
         Call Supsub(Titl,Llabel(I),Iup,Idown)
         If (Sizlab(I) .EQ. 1) Sizes = 1.7
         If (Sizlab(I) .EQ. 2) Sizes = 2.3
         Sizes = Sizes * 0.042
c
c               Account for rotated labels
c
         If (Irot(I) .NE. 0) Then
            Angle = Irot(I)/180.*3.1415926
            Cosine = Cos(Angle)
            Sine = Sin(Angle)
            Xo = Xo - (Just(I)-1)*Rlenth*Cosine/2.0 + Sizes *
     $              0.7 * Sine * Idown
            Yo = Yo - (Just(I)-1)*Rlenth*Sine/2.0 - Sizes *
     $              0.7 * Cosine * Idown
         Else
            Xo = Xo - (Just(I)-1)*Rlenth/2.0
            Yo = Yo - Sizes * 0.7 * Idown
         End If
c
         Sizes = Sizes * (Idown*0.7 + Iup*0.4 + 1.0)
         X1 = Xo
         Y1 = Yo
         If (Irot(I) .NE. 0) Then
            X2 = Xo - Sizes * Sine
            Y2 = Yo + Sizes * Cosine
            X3 = Xo + Rlenth * Cosine - Sizes * Sine
            Y3 = Yo + Rlenth * Sine + Sizes * Cosine
            X4 = Xo + Rlenth * Cosine
            Y4 = Yo + Rlenth * Sine
            Xlmin = Amin1(Xlmin,X2)
            Xlmin = Amin1(Xlmin,X3)
            Xlmin = Amin1(Xlmin,X4)
            Xlmax = Amax1(Xlmax,X1)
            Xlmax = Amax1(Xlmax,X2)
            Xlmax = Amax1(Xlmax,X4)
            Ylmin = Amin1(Ylmin,Y2)
            Ylmin = Amin1(Ylmin,Y3)
            Ylmin = Amin1(Ylmin,Y4)
            Ylmax = Amax1(Ylmax,Y1)
            Ylmax = Amax1(Ylmax,Y2)
            Ylmax = Amax1(Ylmax,Y4)
         Else
            X3 = Xo + Rlenth
            Y3 = Yo + Sizes
         End If
c
         Xlmin = Amin1(Xlmin,X1)
         Ylmin = Amin1(Ylmin,Y1)
         Xlmax = Amax1(Xlmax,X3)
         Ylmax = Amax1(Ylmax,Y3)
c
 10   Continue
c
c               Adjust for X axis text lengths (exceptionally long text)
c
      Do 20 I=1,Xnumbr
         Call Axstgt(Titl,Nchrs,Xaxis,I)
         Call Strlen(Titl,Nchrs,Axchst,Textsz,Rlenth)
         Xlmin = Amin1(Xlmin,Xlen/2.0-Rlenth/2.0)
         Xlmax = Amax1(Xlmax,Xlen/2.0+Rlenth/2.0)
 20   Continue
c
c               Adjust for Y axis text lengths (exceptionally long text)
c
      Do 30 I=1,Ynumbr
         Call Axstgt(Titl,Nchrs,Yaxis,I)
         Call Strlen(Titl,Nchrs,Axchst,Textsz,Rlenth)
         Ylmin = Amin1(Ylmin,Ylen/2.0-Rlenth/2.0)
         Ylmax = Amax1(Ylmax,Ylen/2.0+Rlenth/2.0)
 30   Continue
c
c              Get the text block lengths
c
      Do 40 I=1,Ntxbl
         If (Ntxl(I) .EQ. 0) Go To 40
         Call Yaxln(Yl,I)
         Call Xaxln(Xl,I)
         If (Labcrd .EQ. 0) Then
            Yo = (Txtbly(I) - Ymin(1)) * Ylen / (Ymax(1)-Ymin(1))
            Xo = (Txtblx(I) - Xmin(1)) * Xlen / (Xmax(1)-Xmin(1))
         Else
            Yo = Txtbly(I) * Ylen
            Xo = Txtblx(I) * Xlen
         End If
         Call Locate(X1,X2,Y1,Y2,Xl,Yl,Xo,Yo,Txbloc(I))
c
         Xlmin = Amin1(X1,Xlmin)
         Xlmax = Amax1(X2,Xlmax)
         Ylmin = Amin1(Y1,Ylmin)
         Ylmax = Amax1(Y2,Ylmax)
 40   Continue
c
c          Get the legend size
c
      If (Nleg .GT. 1 .AND. Sizleg .GT. 0) Then
         Call Legsiz(Xlv,Ylv)
c
         If (Labcrd .EQ. 0) Then
            Yo = (Yleg - Ymin(1)) * Ylen / (Ymax(1)-Ymin(1))
            Xo = (Xleg - Xmin(1)) * Xlen / (Xmax(1)-Xmin(1))
         Else
            Yo = Yleg * Ylen
            Xo = Xleg * Xlen
         End If
         Call Locate(X1,X2,Y1,Y2,Xlv,Ylv,Xo,Yo,Locleg)
c
         Xlmin = Amin1(X1,Xlmin)
         Xlmax = Amax1(X2,Xlmax)
         Ylmin = Amin1(Y1,Ylmin)
         Ylmax = Amax1(Y2,Ylmax)
      End If
c
c           Finished sizing
c
      Return
      End
      Subroutine Locate(X1,X2,Y1,Y2,Xlv,Ylv,Xloc,Yloc,Iflag)
c
c ***********************************************************************
c *                                                                     *
c *        Subroutine Locate - To find the corner ordinates of a box    *
c *        given the X and Y lengths, a single coordinate, and a flag   *
c *        which indicates the relative position of the box to that     *
c *        coordinate  (upper left, center, etc.).  This is used by     *
c *        the text blocks and legend.                                  *
c *                                                                     *
c *          Programmed by Steven C. Fisher, DTNSRDC Code 1522          *
c *                                                                     *
c ***********************************************************************
c
      Include 'Caxis'
      Include 'Clabls'
c
      X1 = Xloc
      Y1 = Yloc
      If (Iflag .EQ. 1) Then
         Y2 = Y1
         Y1 = Y1 - Ylv
         X2 = X1 + Xlv
      Else If (Iflag .EQ. 2) Then
         X2 = X1 + Xlv
         Y2 = Y1 + Ylv
      Else If (Iflag .EQ. 3) Then
         X2 = X1
         X1 = X2 - Xlv
         Y2 = Y1
         Y1 = Y2 - Ylv
      Else If (Iflag .EQ. 4) Then
         X2 = X1
         X1 = X2 - Xlv
         Y2 = Y1 + Ylv
      Else If (Iflag .EQ. 5) Then
         X2 = X1 + Xlv/2.0
         X1 = X2 - Xlv
         Y2 = Y1 + Ylv/2.0
         Y1 = Y2 - Ylv
      Else If (Iflag .EQ. 6) Then
         X2 = X1 + Xlv
         Y2 = Y1 + Ylv/2.0
         Y1 = Y2 - Ylv
      Else If (Iflag .EQ. 7) Then
         X2 = X1
         X1 = X2 - Xlv
         Y2 = Y1 + Ylv/2.0
         Y1 = Y2 - Ylv
      Else If (Iflag .EQ. 8) Then
         X1 = X1 - Xlv/2.0
         X2 = X1 + Xlv
         Y2 = Y1
         Y1 = Y2 - Ylv
      Else If (Iflag .EQ. 9) Then
         X1 = X1 - Xlv/2.0
         X2 = X1 + Xlv
         Y2 = Y1 + Ylv
      End If
      Return
      End
      Subroutine Axstgt(Titl,Nchrs,Axis,Nax)
c
c ***********************************************************************
c *                                                                     *
c *         Subroutine Axstgt - This subroutine finds the number of     *
c *         characters in an axis title, and copies it into a one       *
c *         dimensional byte array.                                     *
c *                                                                     *
c *            Programmed by Steven C. Fisher, DTNSRDC Code 1522        *
c *                                                                     *
c ***********************************************************************
c
      Byte Titl(1),Axis(2,80)
c
      Nchrs = 0
      Do 10 I=80,1,-1
         Titl(I) = Axis(Nax,I)
         If (Titl(I) .NE. ' ' .AND. Nchrs .EQ. 0) Nchrs = I
 10   Continue
      If (Nchrs .EQ. 0) Then
         Nchrs = 1
         Titl(1) = ' '
      End If
      Return
      End
      Subroutine Legsiz(Xsiz,Ysiz)
c
c ***********************************************************************
c *                                                                     *
c *          Subroutine Legsiz - To compute the X and Y lengths of the  *
c *          legend, in inches.  This is similar to the routine in      *
c *          PLOTFL.                                                    *
c *                                                                     *
c *            Programmed by Steven C. Fisher, DTNSRDC Code 1522        *
c *                                                                     *
c ***********************************************************************
c
      Include 'Cmain'
      Include 'Clegnd'
      Include 'Caxis'
      Include 'Cdefl'
c
      Xsiz = 0.0
      Nsp = 2
c
c            Get the labels' length, and set a flag for symbols & lines
c
      Do 30 I=2,Nleg
         Call Name(Titl,I,Lableg,Lleg)
         Call Strlen(Titl,Lleg(I),Lechst,Sizleg,Rlenth)
         Xsiz = Amax1(Xsiz,Rlenth)
         If (Symleg(I) .GT. 0 .AND. Nsp .EQ. 2) Nsp = 5
         If (Linleg(I) .GT. 0) Nsp = 12
 30   Continue
c
c              Get the title length
c
      If (Lleg(1) .GT. 0) Then
         Call Strlen(Lableg,Lleg(1),Lechst,Sizleg,Tlen)
         Numleg = Nleg
      Else
         Tlen = 0.0
         Numleg = Nleg - 1
      End If
c
c              Get the size of some spaces
c
      Call Strlen('8',1,Lechst,Sizleg,Xsp)
c
c              Select the larger of the title or labels
c
      If (Tlen .GT. Xsiz + Xsp*Nsp) Xsiz = Tlen - Xsp*Nsp
c
      Xsiz = (Xsp*(Nsp+2) + Xsiz)
      Scale = Sizleg
      If (Sizleg .EQ. 1) Scale = 1.7
      If (Sizleg .EQ. 2) Scale = 2.3
      Ysiz = 0.042 * Scale * (2.0*(Numleg+1) - 0.5)
      Return
      End
      Subroutine Supsub(Strin,Len,Iup,Idown)
c
c ***********************************************************************
c *                                                                     *
c *       Subroutine Supsub - To see if the label has a superscript     *
c *       or subscript.                                                 *
c *                                                                     *
c *          Programmed by Steven C. Fisher, DTNSRDC Code 1522          *
c *                                                                     *
c ***********************************************************************
c
      Byte Strin(1)
c
      Iup = 0
      Idown = 0
      Do 10 I=1,Len-1
        If (Strin(I) .EQ. 64 .AND. Strin(I+1) .EQ. '^') Iup = 1
        If (Strin(I) .EQ. 64 .AND. Strin(I+1) .EQ. '`') Idown = 1
 10   Continue
      Return
      End
      Subroutine Yaxln(Ylen,N)
c
c ***********************************************************************
c *                                                                     *
c *        Subroutine Yaxln - To determine the Y axis length of a       *
c *        text block or a viewgraph.  This uses the same type of       *
c *        methodolgy to compute the Y axis as used by PLOTFL           *
c *        to compute a text block Y extent.  This will not work right  *
c *        for hardware fonts since hardware fonts will not match       *
c *        the text size exactly.                                       *
c *                                                                     *
c *           Programmed by Steven C. Fisher, DTNSRDC Code 1522         *
c *                                                                     *
c ***********************************************************************
c
      Include 'Clabls'
      Include 'Ctxblk'
c
c          Add the height of the label plus the space above the label
c
      Ylen = 0.0
      Nbl = Nlab
      Do 10 I=1,N-1
         Nbl = Nbl + Ntxl(I)
 10   Continue
      Do 40 I=1,Ntxl(N)
         Size = Sizlab(I+Nbl)
         If (Sizlab(I+Nbl) .EQ. 1) Size = 1.7
         If (Sizlab(I+Nbl) .EQ. 2) Size = 2.3
c
c              See if we have to use the global spacing factor.
c
         If (Xlabel(I+Nbl) .GT. 0.0 .AND. I .GT. 1) Then
            Ylen = Ylen + (1.0 + Xlabel(I+Nbl)*Txblsp(N)) * Size * 0.042
         Else
            Ylen = Ylen + (1.0 + Xlabel(I+Nbl)) * Size * 0.042
         End If
         If (I .EQ. 1) Ytop = Size
         If (I .EQ. Ntxl(N)) Ybot = Size
 40   Continue
c
c          Add in the top and bottom border lengths
c
      Ylen = Ylen + 1.7 * Amax1(Ytop,Ybot) * 0.042
      Ylen = Amax1(Ylen,1.0)
      Return
      End
      Subroutine Xaxln(Xlen,N)
c
c ***********************************************************************
c *                                                                     *
c *        Subroutine Xaxln - To determine the X axis length of a       *
c *        text block or a viewgraph.  This uses the same type of       *
c *        methodolgy to compute the X axis as used by PLOTFL           *
c *        to compute a text block X extent.  This will not work right  *
c *        for hardware fonts since hardware fonts will not match       *
c *        the text size exactly.                                       *
c *                                                                     *
c *           Programmed by Steven C. Fisher, DTNSRDC Code 1522         *
c *                                                                     *
c ***********************************************************************
c
      Include 'Cmain'
      Include 'Clabls'
      Include 'Ctxblk'
c
      Xlen = 0.0
      Nbl = Nlab
      Do 10 I=1,N-1
         Nbl = Nbl + Ntxl(I)
 10   Continue
      Do 20 I=1,Ntxl(N)
         Call Name(Titl,Nbl+I,Label,Llabel)
         Idefl = Txblch(N)
         Call Strlen(Titl,Llabel(Nbl+I),Idefl,Sizlab(Nbl+I),Rlenth)
         Call Strlen('8',1,Idefl,Sizlab(Nbl+I),Alenth)
         Xlen = Amax1(Xlen,Rlenth+3.0*Alenth)
 20   Continue
      Xlen = Amax1(Xlen,3.0)
      Return
      End
