      Subroutine SAVPLT(Data,Itype)
c
c ***********************************************************************
c *                                                                     *
c *         Subroutine SAVPLT - To write the current plot presentation  *
c *         to a file.                                                  *
c *                                                                     *
c *         Itype - A flag to determine whether the datapoints should   *
c *                 also be saved in the plot file                      *
c *                  (Itype = 0; no, Itype = 1; yes)                    *
c *                                                                     *
c *          Programmed by Steven C. Fisher, DTNSRDC Code 1522          *
c *                                                                     *
c ***********************************************************************
c
      Include 'Caxis'
      Include 'Cplot'
      Include 'Clegnd'
      Include 'Clabls'
      Include 'Ctxblk'
      Include 'Cgrid'
      Include 'Cmain'
      Include 'Cdefl'
c
      Virtual Data(1)
      Byte Filnam(25)
      Integer*4 Isave
c
      Isave = 0
      Ivers = 8
c
      If (Itype .EQ. 1) Then
         Write(7,100) 27,27,27,32
      Else If (Itype .EQ. 0) Then
         Write(7,100) 27,27,27,' (Short Form - Datapoints Not Included)'
      Else
         Write(7,110)
110      Format(' Enter the file name to store the viewgraph  ',$)
      End If
c
100   Format(1X,1A1,'[H',1A1,'[J'/1X,1A1,'#6 SAVE PRESENTATION',
     $     ' ROUTINE'/A/'   Enter the file name to store the data  '$)
      Read(5,125,END=98,ERR=98) Filnam
125   Format(25A1)
c
c             Check the file name syntax
c
      Call Chknam(Filnam,Iflag)
      If (Iflag .EQ. 1) Return
c
c             Compute the filespace needed
c
      Do 10 I=1,Ncurve
         Isave = Npoint(Xcurve(I)) * 37 * Itype + Isave + 65
         If (Crvfit(I) .EQ. 7 .OR. Crvfit(I) .EQ. 8) Isave = Isave +
     $           Npoint(Cvcol(I)) * 18 + Ttllen(Cvcol(I)) + 12
         Isave = Isave + Ttllen(Xcurve(I)) + Ttllen(Ycurve(I)) + 2
10    Continue
c
      Ntlab = Nlab
      Do 15 I=1,Ntxbl
         Ntlab = Ntlab + Ntxl(I)
 15   Continue
c
      Do 20 I=1,Ntlab
         Isave = Llabel(I) + Isave + 87  ! Space for labels
20    Continue
c
      Do 30 I=1,Nleg
         Isave = Lleg(I) + Isave + 40    ! Space for legend
30    Continue
c
c          Check to see if it is a good file name, and if there is
c          enough room for the data (Isave is the number of blocks needed
c
      Isave = (Isave + 512)/512 + 2
      Isav = Isave              !Switch to 2 byte integer
c
      Call Filchk(Filnam,Isav,Iflag)
c
c           If there is an error with the file name/size/etc, return
c
      If (Iflag .EQ. 1) Return
c
      Open(Unit=12,NAME=Filnam,TYPE='NEW',ERR=98,INITIALSIZE=Isav)
c
      Write(12,*,END=99,ERR=99)  Xlen,Ylen,Textsz,Axchst,Axthik,Spchar,
     $ Itype,Ylen
      Write(12,*,END=99,ERR=99)  Xnumbr,Ynumbr,Axtypx,Axtypy,Ticdir,
     $                              Atxclr
      Write(12,*,END=99,ERR=99)  Xmin,Xmax,Xinc
      Write(12,*,END=99,ERR=99)  Ymin,Ymax,Yinc
      Write(12,*,END=99,ERR=99)  Xgrdmj,Xgrdmr,Ygrdmj,Ygrdmr
      Write(12,*,END=99,ERR=99)  Thikmj,Thikmr,Grdcmj,Grdcmr
      Write(12,*,END=99,ERR=99)  Ivers,Axcolr,Lecolr,Lacolr
      Izero = 0
      Write(12,*,END=99,ERR=99)  Xtop,Izero,Izero,Izero,Izero
c
c         Save the axis titles
c
      Write(12,150,END=99,ERR=99) (Xaxis(1,J),J=1,80)
      Write(12,150,END=99,ERR=99) (Xaxis(2,J),J=1,80)
      Write(12,150,END=99,ERR=99) (Yaxis(1,J),J=1,80)
      Write(12,150,END=99,ERR=99) (Yaxis(2,J),J=1,80)
150   Format(132A1)
      Write(12,*,END=99,ERR=99)  NLab,Lachst,Nleg,Lechst,Ntxbl,Labcrd
      If (Nlab .GT. 0) Then
c
c            Save the labels
c
         Do 40 I=1,Nlab
            Call Point(K,I,Llabel)
            Write(12,150,END=99,ERR=99) (Label(J),J=K,K+Llabel(I)-1)
            Write(12,*,END=99,ERR=99)  Xlabel(I),Ylabel(I),Sizlab(I),
     $           Just(I),Iprot(I),Irot(I)
40       Continue
      End If
c
c              Save the text block data
c
      If (Ntxbl .GT. 0) Then
         K1 = Nlab + 1
         Call Point(K,K1,Llabel)
         Do 43 I=1,Ntxbl
            Write(12,*,END=99,ERR=99) Ntxl(I),Txblch(I),Txblcl(I),
     $           Txbloc(I),Txbord(I),Txtblx(I),Txtbly(I),Txblsp(I)
            Do 41 J=1,Ntxl(I)
               Write(12,150,END=99,ERR=99) (Label(L),L=K,
     $              K+Llabel(K1)-1)
               Write(12,*,END=99,ERR=99) Xlabel(K1),Sizlab(K1),Just(K1)
               K = K + Llabel(K1)
               K1 = K1 + 1
 41        Continue
 43      Continue
      End If
c
      If (Nleg .GT. 0) Then   ! Save legend data
c
         Write(12,175,END=99,ERR=99) Xleg,Yleg,Locleg,Boxleg,Sizleg,
     $          Legsz,Gblspc
175      Format(2G13.5,4I4,G13.5)
c
c             Write the legend labels in the file
c
         Do 50 I=1,Nleg
            Call Point(K,I,Lleg)
            Write(12,150,END=99,ERR=99)  (Lableg(J),J=K,K+Lleg(I)-1)
            Write(12,*,END=99,ERR=99) Symleg(I),Linleg(I),Lcolor(I)
50       Continue
      End If
c
c             Start with the curve data
c
      Write(12,*,END=99,ERR=99) Ncurve,Cvthik,Symbsz
c
      If (Ncurve .GT. 0) Then
         Do 60 I=1,Ncurve
            Write(12,*,END=99,ERR=99) Npoint(Xcurve(I)),Cvline(I),
     $           Cvsymb(I),Crvfit(I),Color(I),Xcvaxi(I),Ycvaxi(I),
     $           Xcurve(I),Ycurve(I)
c
            If (Itype .GT. 0) Then
               Call Name(Titl,Xcurve(I),Title,Ttllen)
               Write(12,150) (Titl(J),J=1,Ttllen(Xcurve(I)))
c
               Call Point(Ipoint,Xcurve(I),Npoint)
               Write(12,200,END=99,ERR=99) (Data(J),J=Ipoint,
     $             Npoint(Xcurve(I)) + Ipoint-1)
c
               Call Name(Titl,Ycurve(I),Title,Ttllen)
               Write(12,150) (Titl(J),J=1,Ttllen(Ycurve(I)))
c
               Call Point(Ipoint,Ycurve(I),Npoint)
               Write(12,200,END=99,ERR=99) (Data(J),J=Ipoint,
     $             Npoint(Ycurve(I)) + Ipoint-1)
200            Format(4G17.9)
            End If
            If (Crvfit(I) .EQ. 7 .OR. Crvfit(I) .EQ. 8) Then
c
c                  For curve fit type 7 (least squares spline)
c
               Write(12,*) Cvcol(I),Npoint(Cvcol(I))
               If (Itype .GT. 0) Then
                  Call Name(Titl,Cvcol(I),Title,Ttllen)
                  Write(12,150) (Titl(J),J=1,Ttllen(Cvcol(I)))
                  Call Point(Ipoint,Cvcol(I),Npoint)
                  Write(12,200,END=99,ERR=99) (Data(J),J=Ipoint,
     $                   Npoint(Cvcol(I)) + Ipoint-1)
               End If
            End If
60       Continue
      End If
c
c          Finished writing the presentation data
c
      Close(Unit=12,ERR=99)
      Return
c
c           Error returns
c
98    Continue
      Write(7,475)
475   Format(' WARNING - Error encountered in opening file - ',
     $         'routine aborted')
      Return
99    Continue
c
      Write(7,500)
500   Format(' WARNING - Error encountered in writing data - ',
     $ 'routine aborted')
      Close(Unit=12,ERR=101)
101   Continue
      Return
c
      End
      Subroutine MODTXT(Ichose)
c
c ***********************************************************************
c *                                                                     *
c *        Subroutine MODTXT - To modify the plot Text Blocks (Or       *
c *        the viewgraphs)                                              *
c *                                                                     *
c *      Programmed by Steven C. Fisher, DTNSRDC Code 1522              *
c *                                                                     *
c ***********************************************************************
c
      Include 'Ctxblk'
c
      Write(7,100) 27,27,27
100   Format(1X,1A1,'[H',1A1,'[J',1X,1A1,'#6 TEXT BLOCK MOD',
     $    'IFICATIONS'/)
c
 10   Continue
c
      Write(7,150) Ntxbl
150   Format(20X,I3,' Text blocks in use'//
     $       ' Select one:'//' A  (A)dd Text blocks'/
     $       ' C  (C)hange text blocks'/
     $       ' D  (D)elete text blocks'/' S  (S)top'//
     $       '  Enter A, C, D, or S:   ',$)
      Call Instrg('AaCcDdSs',8,Ichose)
      Ichose = (Ichose + 1) / 2
c
      If (Ichose .EQ. 3) Then
         If (Ntxbl .LE. 0) Go To 10
         Write(7,200)
200      Format(' Enter the text block number to delete   ',$)
         Call Inchek(1,Ntxbl,Itxt)
         Ichose = -Itxt
      End If
      Return
      End
      Subroutine Adtxbl
c
c ***********************************************************************
c *        Subroutine Adtxbl - To add a text block to the presentation  *
c *                                                                     *
c *         Programmed by Steven C. Fisher, DTNSRDC Code 1522           *
c *                                                                     *
c ***********************************************************************
c
      Include 'Cmain'
      Include 'Ctxblk'
      Include 'Clabls'
      Include 'Cflags'
c
      Character*12 Loc(9)
      Data Loc/'Upper left  ','Lower left  ','Upper right ',
     $         'Lower right ','Center      ','Left center ',
     $         'Right center','Upper center','Lower center'/
c
      Call Lacord(Labcrd)
      Ipflag = 1
      Ntx = Ntxbl + 1
c
c            Set the color and character set to be the same
c            as the labels, and the global spacing factor to 1.0
c
      Txblch(Ntx) = -1
      Txblcl(Ntx) =  0
      Txblsp(Ntx) =  1.0
c
c            Get the text block info - location & border
c
      Write(7,100) Ntx
100   Format(' Adding text block number ',I2/' Enter the X and Y',
     $       ' location of the text block')
      Call Indata(2,'RR',Txtblx(Ntx),Txtbly(Ntx))
      Write(7,150) (K,Loc(K),K=1,9)
150   Format(' Does the X and Y values correspond to the:'//
     $       9(I2,')  ',A12/)/'  Enter 1-9:  ',$)
      Call Inchek(1,9,Txbloc(Ntx))
      Write(7,200)
200   Format(/' Do you want a border drawn around the text block?',
     $       '  (y/n)  ',$)
      Call Instrg('YyNn',4,Ich)
      Txbord(Ntx) = (Ich + 1) / 2
c
c             Get the pointer to the first line of text to add
c
      Nlines = Nlab
      Do 10 I=1,Ntx-1
         Nlines = Nlines + Ntxl(I)
 10   Continue
c
      Ntxl(Ntx) = 0
c
c             Get the labels for the text block
c
 20   Continue
c
      Write(7,250) Ntxl(Ntx) + 1
250   Format(' Enter the text for text block label number ',I2/
     $       ' (press return to stop)')
      Call Linedt(Titl,Len,80,0)
      If (Len .EQ. 0) Return
c
      Ntxl(Ntx) = Ntxl(Ntx) + 1
      Nlines = Nlines + 1
      Call Point(K,Nlines,Llabel)
      J = 0
      Call Rep(Label,K,K,J,Titl,Len)
      Llabel(Nlines) = Len
c
c              Get the label size
c
      Write(7,300)
300   Format(' Enter the text size for the label (1-10)  ',$)
      Call Inchek(1,10,Sizlab(Nlines))
c
c              Get the text justification
c
      Write(7,350)
350   Format(' Enter L, C, or R, for (L)eft, (C)enter, or',
     $       ' (R)ight justification of the label  ',$)
      Call Instrg('LlCcRr',6,Ichose)
      Just(Nlines) = (Ichose + 1) / 2
c
      If (Ntxl(Ntx) .EQ. 1) Ntxbl = Ntxbl + 1
c
      If (Ntxl(Ntxbl) .GT. 1) Then
         Xlabel(Nlines) = Amax1(Sizlab(Nlines)*1.0,
     $                  (Sizlab(Nlines)+Sizlab(Nlines-1))/2.0)/
     $                   Sizlab(Nlines)
      Else
         Xlabel(Nlines) = 0.0
      End If
c
      Go To 20
      End
