      Subroutine MODIFY(Data)
c
c ***********************************************************************
c *                                                                     *
c *        SUBROUTINE MODIFY - To modify the data in a given column,    *
c *        including the column title.  The user can add, change,       *
c *        and/or delete data from a column, and even delete a column.  *
c *        (If a column is deleted, both the table and plot             *
c *        presentations are updated accordingly.                       *
c *                                                                     *
c *           Programmed by Steven C. Fisher, DTNSRDC Code 1522         *
c *                                                                     *
c ***********************************************************************
c
      Include 'Cmain'
      Include 'Cplot'
      Include 'Cflags'
c
      Virtual Data(1)
      Integer Choice
      Dimension Lop(4)
c
c          See if there is data in program
c
      If (Ncols .EQ. 0) Then
         Write(6,100)
100      Format(' ERROR - No Data in the program - routine aborted')
         Return
      End If
c
 5    Continue
c
c          Read in the column number to modify
c
      Write(6,120) 27,27,27
120   Format(1X,1A1,'[H',1A1,'[J'/1X,1A1,'#6   Modify and/or display',
     $ ' data'///5x,'Enter the data column number')
      Call Indata(1,'I',Icol)
c
c         Set the column number between 1 and Ncols
c
      Icol = Max0(1,Icol)
      Icol = Min0(Ncols,Icol)
      Imod = 0
c
c         Get the column title, and the data in the column
c
      Call Name(Titl,Icol,Title,Ttllen)
      Nchar = Ttllen(Icol)
      Call Getvec(Data,Npoint,Icol,X,Number)
      Call Point(Ipoint,Icol,Npoint)
      Call Point(Iend,Ncols+1,Npoint)
10    Continue
c
c         Print out the current data values
c
      Write(6,140) 27,27,Icol,(Titl(I),I=1,Nchar)
140   Format(1X,1A1,'[H',1A1,'[J',' Column Number ',I3,'   Current',
     $ ' data:'//'    0    Data Title : ',<Nchar>A1/)
c
c        See how many columns are needed to print the data out
c
      Nc = Number / 16 + 1
      If (Nc .GT. 4) Nc = 4
      Loop = Number / Nc
      Mod = Number - Loop * Nc
      Lop(1) = 0
      If (Nc .EQ. 1) Go To 18
      Do 15 I=2,Nc
         Lop(I) = Loop +  Lop(I-1)
         If (Mod .GE. (I-1)) Lop(I) = Lop(I) + 1
15    Continue
18    Continue
c
c         Print the data in neat columns
c
      If (Loop .NE. 0) Then
         Do 20 I=1,Loop
            Write(6,160) (I+Lop(K),X(I+Lop(K)),K=1,Nc)
160         Format(4(I5,G15.5))
20       Continue
      End If
      If (Mod .NE. 0) Then
         Write(6,160) (Loop+1+Lop(K),X(Loop+Lop(K)+1),K=1,Mod)
      End If
30    Continue
c
c         Input the modify option
c
      Write(6,180)
180   Format(1X/' Enter (I)nsert, (C)hange, (D)elete, or (S)top  '$)
      Call Instrg('IiCcDdSs',8,Choice)
      Choice = (Choice+1)/2
      If (Choice .LT. 4) Imod = 1
      Go To (40,60,80,92) Choice
40    Continue
c
c  ********************************
c        Insert Data Routine
c  ********************************
c
      Write(6,200)
200   Format(' Enter the number to insert data after  '$)
      Call Inchek(0,Number,Insert)
c
c        Read in the data using Subroutine INPT
c
      Write(6,220)
220   Format(' Input the values to insert - Enter "S" to stop')
      Call Inpt(Y,Numbr,Iflag,1)
c
c        See if array DATA would be overflowed by adding the new data
c
      If (Numbr .GT. Last-Iend+1-Number+Npoint(Icol)) Then
         Write(6,240)
240      Format(' Available data space exceeded - inserted data ',
     $          'truncated')
         Numbr = Last - Iend + 1 - Number + Npoint(Icol)
      End If
      If (Numbr .EQ. 0) Go To 92
c
c        Store the inserted values into X, and update the pointers.
c
      Do 45 I=Number,Insert+1,-1
         X(I+Numbr) = X(I)
45    Continue
      Do 50 I=Insert,Insert+Numbr-1
         X(I+1) = Y(I+1-Insert)
50    Continue
      Number = Number + Numbr
      Go To 10
c
c  **************************************
c          Change Data routine
c  **************************************
c
60    Continue
      Write(6,260)
260   Format(' Enter the number (not value) to change, or (S)top  '$)
      Call INPT(Y,Numbr,Iflag,2)
      If (Iflag .EQ. 1) Go To 10
c
c        Check limits on point number to change
c
      Ichang = Y(1)
      If (Ichang .GE. 0 .AND. Ichang .LE. Number) Then
         If (Ichang .EQ. 0) Then
c
c        Change the title
c
65          Continue
            Write(6,280)
280         Format(' Edit the old title:')
            Call Linedt(Titl,Nchar,80,1)
         Else
c
c                Change the data
c
            Write(6,340) X(Ichang)
340         Format(' Current value is ',G15.6,', New value is?  '$)
            Call Indata(1,'R',X(Ichang))
         End If
      Else
         Write(6,360)
360      Format(' Error in the input value')
      End If
      Go To 60
c
c  *************************************
c          Delete data routine
c  *************************************
c
80    Continue
      Write(6,380)
380   Format(' Enter one point number to delete, or a range [First, ',
     $        'Last] to delete')
      Call INPT(Y,Numbr,Iflag,2)
      Ifirst = Y(1)
      If (Numbr .GT. 1) Then
         Ilast = Y(2)
      Else
         Ilast = Ifirst
      End If
c
c         Check for errors in the point range to delete
c
      If (Ifirst .GT. 0 .AND. Ifirst .LE. Ilast .AND.
     $    Ilast .LE. Number .AND. Numbr .LE. 2) Go To 85
      Write(6,400)
400   Format(' Input data error')
      Go To 80
85    Continue
c
c   ***   Delete the bad data
c
c
c         If the whole column is deleted, then
c
      If (Ilast-Ifirst+1 .EQ. Number) Then
         Number = 0
         Go To 92
      Else
c
c            Only some of the points are deleted
c
         If (Ilast .EQ. Number) Go To 90
         Do 88 I=Ilast,Number-1
            X(Ifirst+I-Ilast) = X(I+1)
88       Continue
c
90       Continue
         Number = Number+Ifirst-Ilast-1
      End If
      Go To 10
92    Continue
c
c ************************************************************
c        See if the data is to be saved (If Imod is zero, no
c        modifications were made to the data
c ************************************************************
c
      If (Imod .EQ. 0) Return
      Write(6,420)
420   Format(' Do you wish to save the modifications?  (y/n)  '$)
      Call Instrg('YyNn',4,Iflag)
      If (Iflag .GT. 2) Return
c
c        Set flag to show data has been modified
c
      Idflag = 1
c
c        Save The Data
c
      If (Number .EQ. 0) Then
c
c         Delete the column if all points are gone
c
         Call Dcols(Data,Icol)
         Return
      Else
c
c          Move the later data columns up or down depending if the column
c          has more or lsee data than before
c
         Idelta = Number - Npoint(Icol)
         If (Number .GT. Npoint(Icol)) Then
c
c             More than before
c
            Do 94 I=Iend-1,Ipoint,-1
               Data(I+Idelta) = Data(I)
94          Continue
         Else
c
c             Less than before
c
            If (Icol .LT. Ncols) Then
               Ipnt = Ipoint + Npoint(Icol+1)
               Do 96 I=Ipnt,Iend-1
                  Data(I+Idelta) = Data(I)
96             Continue
            End If
         End If
c
c           Fill in the new data
c
         Do 98 I=1,Number
            Data(Ipoint-1+I) = X(I)
98       Continue
         Npoint(Icol) = Number
      End If
c
c        Save the new title
c
      Call Point(Ittl,Icol,Ttllen)
      Call Point(Itend,Ncols+1,Ttllen)
      Itend = Itend-1
      Call Rep(Title,Itend,Ittl,Ttllen(Icol),Titl,Nchar)
      Ttllen(Icol) = Nchar
c
      Return
      End
      Subroutine Dcols(Data,Icol)
c
c ***********************************************************************
c *                                                                     *
c *         Subroutine DCOLS - To delete unwanted columns from the      *
c *         array DATA.  It also updates the table and plot             *
c *         presentations, deleting the table columns and               *
c *         any curve whose columns have been deleted, and updating     *
c *         the column pointers for the other curves.                   *
c *                                                                     *
c *          Programmed by Steven C. Fisher, DTNSRDC Code 1522          *
c *                                                                     *
c ***********************************************************************
c
      Include 'Cmain'
      Include 'Cplot'
      Include 'Ctable'
      Include 'Cflags'
c
      Virtual Data(1)
c
c         Find the starting location of the data in DATA
c
      Call Point(Ipoint,Icol,Npoint)
      Call Point(Iend,Ncols+1,Npoint)
c
c         Move the data up in DATA, writing over the old values
c
      Do 20 I=Ipoint,Iend-1-Npoint(Icol)
         Data(I) = Data(I+Npoint(Icol))
20    Continue
c
c          Remove column title
c
      Call Point(Ittl,Icol,Ttllen)
      Call Point(Itend,Ncols+1,Ttllen)
      Itend = Itend-1
      Call Rep(Title,Itend,Ittl,Ttllen(Icol),' ',0)
c
c          Update the pointers
c
      If (Icol .LT. Ncols)  Then
         Do 30 I=Icol,Ncols-1
            Npoint(I) = Npoint(I+1)
            Ttllen(I) = Ttllen(I+1)
30       Continue
      End If
      Ncols = Ncols-1
c
c          Update the table presentation to reflect the deleted column
c
      If (Ntab .GT. 1) Then
c
         K = 2
 35      Continue
         If (Icol .EQ. Tabcol(K)) Then
            Call Tabdel(K,1)
            Itflag = 1
         Else If (Icol .LT. Tabcol(K)) Then
            Tabcol(K) = Tabcol(K) - 1
            K = K + 1
            Itflag = 1
         Else
            K = K + 1
         End If
         If (K .LE. Ntab) Go To 35
c
      End If
c
c          Update the plot presentation to reflect the deleted column
c
      If (Ncurve .GT. 0) Then
         K = 1
40       Continue
         If (K .GT. Ncurve) Return
         If (Xcurve(K) .EQ. Icol .OR. Ycurve(K) .EQ. Icol .OR.
     $      ((Crvfit(K) .EQ. 8 .OR. Crvfit(K) .EQ. 7) .AND. 
     $        Cvcol(K) .EQ. Icol)) Then
c
c            Remove the curve from the presentation
c
            Ipflag = 1
            If (K .NE. Ncurve) Then
               Do 50 I=K,Ncurve-1
                  Xcurve(I) = Xcurve(I+1)
                  Ycurve(I) = Ycurve(I+1)
                  Cvline(I) = Cvline(I+1)
                  Cvsymb(I) = Cvsymb(I+1)
                  Crvfit(I) = Crvfit(I+1)
                  Xcvaxi(I) = Xcvaxi(I+1)
                  Ycvaxi(I) = Ycvaxi(I+1)
                  Color(I)  = Color(I+1)
                  Cvcol(I)  = Cvcol(I+1)
50             Continue
            End If
            Ncurve = Ncurve - 1
         Else
c
c              Update the curve pointers
c
            If ((Xcurve(K) .GT. Icol) .OR. (Ycurve(K) .GT. Icol)
     $           .OR. (Cvcol(K) .GT. Icol)) Ipflag = 1
            If (Xcurve(K) .GT. Icol) Xcurve(K) = Xcurve(K)-1
            If (Ycurve(K) .GT. Icol) Ycurve(K) = Ycurve(K)-1
            If (Cvcol(K) .GT. Icol) Cvcol(K) = Cvcol(K) - 1
         K = K + 1
         End If
c
         Go To 40
c
      End If
c
      Return
      End
      Subroutine DELCOL(Data)
c
c ***********************************************************************
c *                                                                     *
c *        Subroutine DELCOL - To delete a number of columns from the   *
c *        stored data values. Both the table and plot presentations    *
c *        are updated to reflect the deleted columns                   *
c *                                                                     *
c *          Programmed by Steven C. Fisher, DTNSRDC Code 1522          *
c *                                                                     *
c ***********************************************************************
c
      Include 'Cmain'
      Include 'Cflags'
c
      Virtual Data(1)
c
      Write(6,100) 27
100   Format(/1X,1A1,'#6    DELETE DATA COLUMN ROUTINE'/)
10    Continue
c
c        Input the column numbers
c
      Write(6,125)
125   Format(' 1)  Delete individual data columns'/
     $       ' 2)  Delete a range [first,last] of data columns'/
     $       ' 3)  Delete all data columns'/
     $       '   Enter 1-3, or S to stop:  ',$)
 15   Continue
      Call Inpt(X,I,Iflag,2)
      Ichose = X(1)
c
      If (Iflag .EQ. 1) Return
c
      If (Ichose .LT. 1 .OR. Ichose .GT. 3) Then
         Write(6,135)
135      Format(' Bad value.  Try again')
         Go To 15
      End If
c
      If (Ichose .EQ. 1) Then
         Write(6,150)
150      Format(' Enter the data column numbers to delete - enter',
     $          ' an "S" to stop')
         Call Inpt(X,Number,Iflag,1)
         If (Number .EQ. 0) Then
            Write(6,200)
200         Format(' No column numbers input - routine aborted')
            Return
         End If
c
c        See if the column numbers are valid
c
         Call Sort(X,Y,Number)
         Do 20 I=1,Number
c
c              Also look for multiple column definitions
c
            If ( X(I) .GT. Ncols .OR. X(I) .LT. 1 .OR. X(I) .EQ.
     $                 X(I-1)) Then
               Write(6,250)
250            Format(' ERROR - Bad column number(s)')
               Go To 10
            End If
20       Continue
      Else If (Ichose .EQ. 2) THen
c
c                Delete a range of data columns
c
         Write(6,275)
275      Format(' Enter the range of columns [first,last] to ',
     $          'delete:  ',$)
         Call Indata(2,'RR',X(1),X(2))
         Ifirst = X(1)
         Ilast  = X(2)
         If (Ifirst .LT. 1 .OR. Ifirst .GT. Ilast .OR. Ilast .GT.
     $              Ncols) Then
            Write(6,250)
            Go To 10
         End If
         Do 25 I=Ifirst,Ilast
            X(I-Ifirst+1) = I
 25      Continue
         Number = Ilast - Ifirst + 1
      Else If (Ichose .EQ. 3) Then
c
c                 Delete all data columns
c
         Write(6,285) 27,27
285      Format(' Do you really want to delete ',1A1,'[4mALL',1A1,
     $          '[0m of the data columns?  (y/n)  ',$)
         Call Instrg('YyNn',4,Ich)
         If (Ich .GT. 2) Return
         Number = Ncols
         Do 27 Icol=Number,1,-1
            Call Dcols(Data,Icol)
 27      Continue
         Return
      End If
c
c            Write out the column titles to see if the user agrees
c
      Write(6,300) 27,27
300   Format(/3X,1A1,'[1;7mCOLUMNS TO BE DELETED:',1A1,'[0m'//
     $       ' No.          Title'/)
      Do 30 I=1,Number
         Icol = X(I)
         Call Name(Titl,Icol,Title,Ttllen)
         Write(6,350) Icol,(Titl(J),J=1,Ttllen(Icol))
350      Format(I4,3x,80(:,A1))
30    Continue
c
c           Ask the user if they are correct
c
      Write(6,400)
400   Format(/' Are the columns correct?  (y/n)  '$)
      Call Instrg('YyNn',4,Iflag)
      If (Iflag .GT. 2) Then
         Write(6,450)
450      Format(' Do you want to stop?  (y/n)  '$)
         Call Instrg('YyNn',4,Iflag)
         If (Iflag .LE. 2) Return
         Go To 10
      End If
c
c        Set flag showing the data has been changed
c
      Idflag = 1
c
c        Delete the columns
c
      Do 40 I=1,Number
         Icol = X(Number-I+1)
         Call Dcols(Data,Icol)
40    Continue
c
c         List out the new columns
c
      Icol = X(1)
      If (Icol .GT. Ncols) Then
         Write(6,475) 27,27
475      Format(1X,1A1,'[5m No Column Numbers Have Changed',1A1,'[0m')
      Else
         Call Lisrng('CHANGED',7,Icol,Ncols)
         Write(6,500) 27,27
500      Format(/1X,1A1,'[5m THE ABOVE ARE THE ONLY COLUMNS WHOSE ',
     $          'NUMBERS HAVE CHANGED',1A1,'[0m')
      End If
      Return
      End
