c
c   Copyright (c) 1990 by Dwight Meglan
c
      subroutine DoGraph( CMND,MACRO,ratio,error )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'
      include 'tel_name.inc'

      include 'vogle.fi'

      record /CmndLine/    CMND
      record /MacroStuff/  MACRO
                              
      real*4    ratio
      logical*4 error
                                                 
      real*4    VpWidth,VpHeight,VpYMin,VpYMax,VpXMin,VpXMax
      integer*4 i,j,NumGraph,FileNum,size,GrNum,GraphInRow,GrPerRow,key
      character line*80,junk*1
      logical*4 SameXData,FirstLine

      save NumGraph,FileNum
c
c     Check for special case of redisplay of previous graph 
c
      if ( CMND.CmndText(2) .eq. 'PRE' ) then
        if ( GD(1).NumPlts .gt. 0 ) then
          goto 10
        else
          goto 1030 ! cannot redisplay previous graph 
        end if
      end if
c                            
c     Check for options
c                         
      SameXData= .true.                  
      NumGraph= 1
      if ( CMND.NumOpt(1) .gt. 0 ) then
        do i= 1, CMND.NumOpt(1)
          if ( CMND.OptText(i,1) .eq. 'DFX' ) then
            SameXData= .false.
          else if ( CMND.OptText(i,1) .eq. 'SAM' ) then
            SameXData= .true.
          else if ( (CMND.OptIntVal(i,1) .ge. 1) .and. 
     &              (CMND.OptIntVal(i,1) .le. MAX_GRAPH) ) then
            NumGraph= CMND.OptIntVal(i,1)
            if ( NumGraph .gt. MAX_GRAPH ) goto 1000 ! error, too many graphs
          else
            goto 1010 ! error, bad option
          end if
        end do    
      end if ! Options present
c
c     Reset foot and force plate outline flags...
c
      do GrNum= 1, MAX_GRAPH
        do i= 1, 2
          GD(GrNum).ShowFtOutline(i)= .false.
        end do
        GD(GrNum).FtOutLineGCS= .true.
        GD(GrNum).ShowFpOutline= .false.
      end do      
c                                               
c     Interpret parameters of each graph and set up data structure for each
c
      FirstLine= .true.                       
      if ( CMND.NumCmnd .eq. 1 ) then ! prompt for first graph
        if ( MACRO.On ) then
          line= MACRO.Text(MACRO.LineNum,MACRO.MacroNum)
          MACRO.LineNum= MACRO.LineNum + 1
        else
          write(6,100) 1
100       format(' graph ',i1,'> ',$)
          read(5,110,end=999) line ! CntrlZ kicks out of subroutine
110       format(a80)
        end if
      else ! remove first entry
        do i= 1, 80
          line(i:i)= ' '
        end do
        line= CMND.Text(1)(CMND.CmndStart(2):80)
      end if         
      call ParseLine( line,CMND )
      i= 1                                  
      error= .false.                                 
      do while (i .le. NumGraph )
        if ( error .and. MACRO.On ) goto 1020 ! error
        if ( (.not. FirstLine) .or. error ) then
          if ( MACRO.On .and. 
     &        (MACRO.LineNum .le. MACRO.NumLines(MACRO.MacroNum)) ) then
            line= MACRO.Text(MACRO.LineNum,MACRO.MacroNum)
            MACRO.LineNum= MACRO.LineNum + 1
          else
            write(6,100) i
            read(5,110,end=999)  line ! CntrlZ kicks out of subroutine
          end if
          call ParseLine( line,CMND )                                
          if ( CMND.CmndText(1) .eq. 'GRA' ) then    ! Special because I keep
            line= CMND.Text(1)(CMND.CmndStart(2):80) ! recalling previous line
            call ParseLine( line,CMND )              ! and getting invalid GRA !
          end if      
        end if             
        if ( ((CMND.NumCmnd .gt. 2) .and. (.not. CMND.Continue))
     &       .or. (CMND.CmndText(1) .eq. 'BLA')                  ) then
          write(6,101)
101       format(/)
          call AssignPlotData( CMND,i,SameXData,
     &                         GD(i).NumPlts,GD(i).Min,GD(i).Max,error )
          if ( .not. error ) then
            if (.not. GD(i).BlankGraph ) then
              GD(i).SameFile= .true.
              FileNum= PD(1,i).FileNum(y)
              do j= 2, GD(i).NumPlts
                if ( PD(j,i).FileNum(y) .ne. FileNum ) GD(i).SameFile= .false.
              end do
              if ( GROPT(i).GrLabelFlg ) then
                if ( GROPT(i).ManGrLabelFlg ) then
                  GD(i).GrLabel= GROPT(i).ManGrLabel
                else
                  GD(i).GrLabel= FD(FileNum).GP.Name
                end if
              end if
            end if ! graph not blank...
            i= i + 1
          end if
        else if ( .not. CMND.Continue ) then
          write(6,120)         
120       format(' Error- Not enough parameters.  Try graph again.')
          error= .true.
        end if            
        FirstLine= .false.
      end do ! while
c                 
c     All graph data has been successfully assigned to graph structure.
c     Now display it.
c                                         
c       Set up the ViewPort         
c           

 10   call clear

      if ( GROPT(1).Screen ) then
         call TurnScreenOn(ratio)
         if ( NumGraph .eq. 1 ) then  
            VpWidth=  2.0                        
            VpHeight= 2.0*ratio
            GrPerRow= 1
            VpYmin= -ratio
            VpYmax=  ratio
            VpXmin= -1.0
            VpXmax=  1.0
         else if ( NumGraph .eq. 2 ) then
            VpWidth=  2.0
            VpHeight= ratio
            GrPerRow= 1
         else if ( (NumGraph .eq. 3) .or. (NumGraph .eq. 4) ) then
            VpWidth=  1.0
            VpHeight= ratio
            GrPerRow= 2
         else if ( (NumGraph .eq. 5) .or. (NumGraph .eq. 6) ) then
            VpWidth=  2.0/3.0
            VpHeight= ratio
            GrPerRow= 3
         else if ( (NumGraph .ge. 7) .and. (NumGraph .le. 9) ) then
            VpWidth=  2.0/3.0
            VpHeight= 2.0*ratio/3.0
            GrPerRow= 3
         else if ( (NumGraph .ge. 10) .and. (NumGraph .le. 12) ) then
            VpWidth=  2.0/4.0
            VpHeight= 2.0*ratio/3.0
            GrPerRow= 4
         else if ( (NumGraph .ge. 13) .and. (NumGraph .le. 15) ) then
            VpWidth=  2.0/5.0
            VpHeight= 2.0*ratio/3.0
            GrPerRow= 5
         end if        
         if ( NumGraph .gt. 1 ) then
            VpYmax=  ratio
            VpYmin=  VpYmax - VpHeight
            VpXmin= -1.0
            VpXmax=  VpXmin + VpWidth
         end if

         call GraphThemAll( VpXmin,VpXmax,VpYmin,VpYmax,ratio,
     &                      VpWidth,VpHeight,NumGraph,GrPerRow )
         key= getkey()
         if ( .not. GROPT(1).Print ) call clear()
      end if

      if ( GROPT(1).Print ) then
         call clear()
         write(6,99)
 99      format(' Writing graph to file...',$)
         call TurnPrinterOn(ratio)
         if ( NumGraph .eq. 1 ) then  
            VpWidth=  2.0                        
            VpHeight= 2.0*ratio
            GrPerRow= 1
            VpYmin= -ratio
            VpYmax=  ratio
            VpXmin= -1.0
            VpXmax=  1.0
         else if ( NumGraph .eq. 2 ) then
            VpWidth=  2.0
            VpHeight= ratio
            GrPerRow= 1
         else if ( (NumGraph .eq. 3) .or. (NumGraph .eq. 4) ) then
            VpWidth=  1.0
            VpHeight= ratio
            GrPerRow= 2
         else if ( (NumGraph .eq. 5) .or. (NumGraph .eq. 6) ) then
            VpWidth=  2.0/3.0
            VpHeight= ratio
            GrPerRow= 3
         else if ( (NumGraph .ge. 7) .and. (NumGraph .le. 9) ) then
            VpWidth=  2.0/3.0
            VpHeight= 2.0*ratio/3.0
            GrPerRow= 3
         else if ( (NumGraph .ge. 10) .and. (NumGraph .le. 12) ) then
            VpWidth=  2.0/4.0
            VpHeight= 2.0*ratio/3.0
            GrPerRow= 4
         else if ( (NumGraph .ge. 13) .and. (NumGraph .le. 15) ) then
            VpWidth=  2.0/5.0
            VpHeight= 2.0*ratio/3.0
            GrPerRow= 5
         end if        
         if ( NumGraph .gt. 1 ) then
            VpYmax=  ratio
            VpYmin=  VpYmax - VpHeight
            VpXmin= -1.0
            VpXmax=  VpXmin + VpWidth
         end if

         call GraphThemAll( VpXmin,VpXmax,VpYmin,VpYmax,ratio,
     &	                    VpWidth,VpHeight,NumGraph,GrPerRow )
         call clear()
         call vflush()
         call TurnScreenOn(ratio)
         write(6,98)
 98      format(' Done.')
      end if

999   return     

1000  write(6,1005) MAX_GRAPH
1005  format(' Error- Too many graphs indicated in options.  Max of ',
     &       i2,' allowed')
      return

1010  write(6,1015) MAX_GRAPH
1015  format(' Error- Invalid option for GRAph command.'/
     &       '        Valid options are: 1-',i2,' (# of graphs)'/
     &       '                           DiFfernt x data'/
     &       '                           SAMe x data')
      return

1020  write(6,1025)
1025  format(' Error- Problem in creating graph during macro execution')
      return

1030  write(6,1035)
1035  format(' Error- Cannot redisplay previous graph because no graph'/
     &       '        has been defined yet.')
      return
      end                                 
c
c
c
      subroutine GraphThemAll( VpXmin,VpXmax,VpYmin,VpYmax,ratio,
     &	                       VpWidth,VpHeight,NumGraph,GrPerRow )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'

      include 'vogle.fi'

      real*4    VpXmin,VpXmax,VpYmin,VpYmax,ratio,VpWidth,VpHeight
      integer*4 NumGraph,GrPerRow

      integer*4 GraphInRow,i

      GraphInRow= 1
      do i= 1, NumGraph
        if ( GD(i).BlankGraph ) then
          call DisplayBlankText( i,VpXmin,VpXmax,VpYmin,VpYmax,ratio )
          call vflush
        else
           call DrawGraph( i,VpXmin,VpXmax,VpYmin,VpYmax,ratio )
           call vflush
        end if
        if ( GraphInRow .eq. GrPerRow ) then
          VpYmax=  VpYmin
          VpYmin=  VpYmax - VpHeight
          if ( VpYmin .lt. -ratio ) VpYmin= -ratio
          VpXmin=  -1.0
          VpXmax=  VpXmin + VpWidth
          GraphInRow= 1
        else
          VpXmin= VpXmax
          VpXmax= VpXmin + VpWidth
          GraphInRow= GraphInRow + 1
        end if
        if ( VpXmax .gt. 1.0 ) VpXmax= 1.0
      end do               

      return
      end

c                       
c   Copyright (c) 1990 by Dwight Meglan                             
c
      subroutine AssignPlotData( CMND,GrNum,SameXData,NumPlts,
     &                           DataMin,DataMax,error )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'
      include 'tel_name.inc' 

      record /CmndLine/    CMND
      real*4    DataMin(2),DataMax(2)
      integer*4 GrNum                  
      logical*4 SameXData,error
                              
      integer*4 Numplts,cn,axis,VarNum,DefFileNum,tempcn,XDataType,XDataVarNum,
     &          Xcn,i,j,k,EventFrmNum(5),Order,tempEvent(MAX_PLOT_SIZE,2),plt
      real*4    temp(MAX_PLOT_SIZE),TempPnt
      logical*4 MrkCmnd,SegCmnd,JntCmnd,FrcCmnd,RecCmnd,TimeCmnd,FirstPlot,
     &          MslCmnd,EventOrderOK,tempOK(MAX_PLOT_SIZE),
     &          NegatePlotData(2,MAX_PLOT),NoAlignSides(MAX_PLOT),
     &          DontNormalize(MAX_PLOT)
c      character TempLine*80
c      record /CmndLine/ Legend
c
c     Right at the start check for a blank graph command...
c
      if ( CMND.CmndText(1) .eq. 'BLA' ) then
        call InterpretBlank( CMND,GrNum,error )
        if ( error ) goto 999
        GD(GrNum).BlankGraph= .true.
        return
      else
        GD(GrNum).BlankGraph= .false.
      end if
c
c     Do some initialization
c
      NumPlts= 0
      cn= 1 
      error= .true.
      axis= x                                           
      FirstPlot= .true. 
      do i= 1, MAX_PLOT
        NoAlignSides(i)= .false.
        DontNormalize(i)= .false.
        do j= 1, 2
          NegatePlotData(j,i)= .false.
        end do                
      end do
      do while ( (cn .le. CMND.NumCmnd) .and. (NumPlts .lt. MAX_PLOT) )
        DefFileNum= GROPT(GrNum).DefFile
c
c       Before deciding which quantity is to be graphed, check for a NEGative
c       option in CMND.OptText( ,cn) and if it is present, remove it from the
c       the options for this plot and set the NegateData flag so that the data
c       will be negated after it has been read into PlotData
c
c       Also, allow NOAlignsides option which only applies to the normal data
c       which came from the OSU true files which is already time aligned on
c       both sides
c
c       Also, check for the NONormalize option which is used with data that
c       has been imported to Analyze in an already normalized form and thus
c       shouldn't be normalized again.  This option was specifically created
c       so that the moment and power normals in David Winter's book could be
c       incorporated into TELIO's graphs.
c
        if ( CMND.NumOpt(cn) .gt. 0 ) then
          i= 1
          do while ( i .le. CMND.NumOpt(cn) )
            if ( CMND.OptText(i,cn) .eq. 'NGX' ) then
              NegatePlotData(x,NumPlts+1)= .true.
              call RemoveCmndOpt( CMND,cn,i )
              i= i - 1
            else if ( CMND.OptText(i,cn) .eq. 'NGY' ) then
              NegatePlotData(y,NumPlts+1)= .true.
              call RemoveCmndOpt( CMND,cn,i )
              i= i - 1
            else if ( CMND.OptText(i,cn) .eq. 'NOA' ) then
              NoALignSides(NumPlts+1)= .true.
              call RemoveCmndOpt( CMND,cn,i )
              i= i - 1
            else if ( CMND.OptText(i,cn) .eq. 'NON' ) then
              DontNormalize(NumPlts+1)= .true.
              call RemoveCmndOpt( CMND,cn,i )
              i= i - 1
            end if
            i= i + 1
          end do                         
        end if                  
c                               
c       Check for marker data        
c                       
        if ( MrkCmnd(CMND.CmndText(cn),VarNum) ) then
          tempcn= cn
          call AssignMrkData( cn,CMND,VarNum,DefFileNum,
     &                        axis,NumPlts+1,GrNum,error )
          if ( error ) goto 999
          if ( SameXData .and. FirstPlot ) then
            XDataType= MRK_DT
            XDataVarNum= VarNum
            Xcn= tempcn
          end if    
c
c       Check for segment data
c                             
        else if ( SegCmnd(CMND.CmndText(cn),VarNum) ) then
          tempcn= cn         
          call AssignSegData( cn,CMND,VarNum,DefFileNum,
     &                        axis,NumPlts+1,GrNum,
     &                        DontNormalize(NumPlts+1),error )
          if ( error ) goto 999
          if ( SameXData .and. FirstPlot ) then
            XDataType= SEG_DT
            XDataVarNum= VarNum
            Xcn= tempcn
          end if
c                                             
c       Check for joint data
c      
        else if ( JntCmnd(CMND.CmndText(cn),VarNum) ) then
          tempcn= cn         
          call AssignJntData( cn,CMND,VarNum,DefFileNum,
     &                        axis,NumPlts+1,GrNum,
     &                        DontNormalize(NumPlts+1),error )
          if ( error ) goto 999
          if ( SameXData .and. FirstPlot ) then
            XDataType= JNT_DT
            XDataVarNum= VarNum
            Xcn= tempcn
          end if
c                                             
c       Check for force data                
c                                           
        else if ( FrcCmnd(CMND.CmndText(cn),VarNum) ) then
          tempcn= cn         
          call AssignFrcData( cn,CMND,VarNum,DefFileNum,
     &                        axis,NumPlts+1,GrNum,
     &                        DontNormalize(NumPlts+1),error )
          if ( error ) goto 999
          if ( SameXData .and. FirstPlot ) then
            XDataType= FRC_DT
            XDataVarNum= VarNum
            Xcn= tempcn
          end if    
c                                           
c       Check for reconstructed ground reaction data
c
        else if ( RecCmnd(CMND.CmndText(cn),VarNum) ) then
          tempcn= cn         
          call AssignRecData( cn,CMND,VarNum,DefFileNum,
     &                        axis,NumPlts+1,GrNum,error )
          if ( error ) goto 999
          if ( SameXData .and. FirstPlot ) then
            XDataType= REC_DT
            XDataVarNum= VarNum
            Xcn= tempcn
          end if
c                                                          
c       Check for muscle data
c
        else if ( MslCmnd(CMND.CmndText(cn),VarNum) ) then
          tempcn= cn         
          call AssignMslData( cn,CMND,VarNum,DefFileNum,
     &                        axis,NumPlts+1,GrNum,error )
          if ( error ) goto 999
          if ( SameXData .and. FirstPlot ) then
            XDataType= MSL_DT
            XDataVarNum= VarNum
            Xcn= tempcn
          end if
c                   
c       Check for EMG Data
c
        else if ( CMND.CmndText(cn) .eq. 'EMG' ) then
          tempcn= cn         
          VarNum= EMG_DATA
          call AssignEmgData( cn,CMND,VarNum,DefFileNum,
     &                        axis,NumPlts+1,GrNum,error )
          if ( error ) goto 999
          if ( SameXData .and. FirstPlot ) then
            XDataType= EMG_DT
            XDataVarNum= VarNum
            Xcn= tempcn
          end if         
c                   
c       Check for cycle, time, frame # quantities       
c                                   
        else if ( TimeCmnd(CMND.CmndText(cn),VarNum) ) then
          if ( .not. FirstPlot ) goto 1020 ! error
          if ( .not. SameXData ) goto 1030 ! error
          if ( VarNum .ne. PCT_DATA ) GROPT(GrNum).PctCycleLn= .false.
          XDataType= TIM_DT
          XDataVarNum= VarNum            
          Xcn= cn        
          cn= cn + 1
c                   
c       If not a mrk, seg, jnt, frc, rec, emg or time command then 
c       command is an error
c      
        else            
          write(6,100) CMND.CmndText(cn),(VarNames(k),k=1,70)
100       format(' Error- ',a3,' is an invalid graph quantity'/
     &           '        Valid quantities are: ',12(a3,1x)/
     &           5(30x,12(a3,1x)/) )
          return           
        end if
c
c       Update number of plots and default plot file number
c                                                       
        if ( (axis .eq. x) .and. (XDataType .ne. TIM_DT) ) 
     &     DefFileNum= PD(NumPlts+1,GrNum).FileNum(x)
        if ( SameXData .and. (.not. FirstPlot) ) then
          NumPlts= NumPlts + 1
        else if ( SameXData .and. FirstPlot ) then
          FirstPlot= .false.
          axis= y
        else if ( axis .eq. y ) then
          NumPlts= NumPlts + 1
        end if          
c
c       Determine which axis the next set of data describes
c                       
        if ( .not. SameXData ) then
          if ( axis .eq. x ) then
            axis= y
          else
            axis= x
          end if
        end if             
      end do ! i => cmnd number
c         
c     If same x values are being used for all plots then assign the x values
c     for plot 1 to the rest of the plots
c
      if ( SameXData ) then                                         
        do i= 1, NumPlts
          tempcn= Xcn
          if ( XDataType .eq. MRK_DT ) then
            call AssignMrkData( tempcn,CMND,XDataVarNum,
     &                          PD(i,GrNum).FileNum(y),x,i,GrNum,error )
            if ( error ) goto 999
          else if ( XDataType .eq. SEG_DT ) then
            call AssignSegData( tempcn,CMND,XDataVarNum,
     &                          PD(i,GrNum).FileNum(y),x,i,GrNum,
     &                          DontNormalize(NumPlts+1),error )
            if ( error ) goto 999
          else if ( XDataType .eq. JNT_DT ) then
            call AssignJntData( tempcn,CMND,XDataVarNum,
     &                          PD(i,GrNum).FileNum(y),x,i,GrNum,
     &                          DontNormalize(NumPlts+1),error )
            if ( error ) goto 999
          else if ( XDataType .eq. FRC_DT ) then
            call AssignFrcData( tempcn,CMND,XDataVarNum,
     &                          PD(i,GrNum).FileNum(y),x,i,GrNum,
     &                          DontNormalize(NumPlts+1),error )
            if ( error ) goto 999
          else if ( XDataType .eq. REC_DT ) then
            call AssignRecData( tempcn,CMND,XDataVarNum,
     &                          PD(i,GrNum).FileNum(y),x,i,GrNum,error )
            if ( error ) goto 999                         
          else if ( XDataType .eq. MSL_DT ) then
            call AssignMslData( tempcn,CMND,XDataVarNum,
     &                          PD(i,GrNum).FileNum(y),x,i,GrNum,error )
            if ( error ) goto 999
          else if ( XDataType .eq. EMG_DT ) then    
            call AssignEmgData( tempcn,CMND,XDataVarNum,
     &                          PD(i,GrNum).FileNum(y),x,i,GrNum,error )
            if ( error ) goto 999
          else if ( XDataType .eq. TIM_DT ) then
            call AssignTimeData( tempcn,CMND,XDataVarNum,
     &                           PD(i,GrNum).FileNum(y),x,i,GrNum,error )
            if ( error ) goto 999
          end if
        end do ! i => plt #
      end if ! all plots have the same x axis quantity
c
c     Now that all data has been assigned to the x and y parts of PltData
c     check whether any of its parts need to be negated and if so do it !!
c                 
      do plt= 1, NumPlts
        do axis= x, y
          if ( NegatePlotData(axis,plt) ) then
            do i= 1, PD(plt,GrNum).NumPnts
              PltData(i,axis,plt,GrNum)= -PltData(i,axis,plt,GrNum)
            end do
            TempPnt= -PD(plt,GrNum).Min(axis)
            PD(plt,GrNum).Min(axis)= -PD(plt,GrNum).Max(axis)
            PD(plt,GrNum).Max(axis)= TempPnt
          end if
        end do
      end do
c                 
c     Now check whether somehow in the above data assigning process data
c     from two different file #'s were assigned to the x and y axes of the
c     same plot.  If so, call this an error.  Also check whether the x and
c     y data types are compatible- they are incompatible if one is motion
c     data and the other is electrical data and the electrical data has
c     not been aligned and clipped. 
c                                                  
      do i= 1, NumPlts                             
        if ( PD(i,GrNum).FileNum(x) .ne. PD(i,GrNum).FileNum(y) ) goto 1000 ! error
        if ( ((PD(i,GrNum).DataType(x) .eq. ELC_DT) .or.
     &        (PD(i,GrNum).DataType(x) .eq. FRC_DT)     ) .and.
     &       ((PD(i,GrNum).DataType(y) .ne. ELC_DT) .and.
     &        (PD(i,GrNum).DataType(y) .ne. FRC_DT)      ) ) then
          if ( .not. FD(PD(i,GrNum).FileNum(x)).FF.IndFt ) goto 1010
        end if
      end do               
c
c     Check whether percent cycle line can be displayed
c
      do i= 1, NumPlts
        if ( PD(i,GrNum).DataType(x) .ne. TIM_DT ) then
          GROPT(GrNum).PctCycleLn= .false.
        else
          GROPT(GrNum).PctCycleLn= .true.
        end if
      end do
c                                                         
c     Check whether data from both sides of body is to be aligned and if so
c     then rearrange the data in the yaxis data field.
c     This can only be done if the data is clipped to a single gait cycle,
c     a valid sequence of gait events is present, and all y axis data is
c     plotted against the same x axis data which must be percent gait.  
c     This is a very restrictive set of conditions, but then this is a very 
c     restrictive type of graphing option.                   
c
      if ( GROPT(GrNum).AlignSides ) then
        if ( .not. SameXdata ) goto 1040
        if ( PD(1,GrNum).DataType(x) .ne. TIM_DT ) goto 1050
        if ( .not. GROPT(GrNum).CycleClip ) goto 1070
        do i= 1, NumPlts
          if ( .not. NoAlignSides(i) ) then
            if ( .not. EventOrderOK( PltEvent(1,y,i,GrNum),
     &                               PD(i,GrNum).NumPnts,
     &                               Order,EventFrmNum)    ) goto 1060
            if ( (Order .eq. lf) .and. (PD(i,GrNum).Side(y) .eq. rt) .or.
     &           (Order .eq. rt) .and. (PD(i,GrNum).Side(y) .eq. lf)   ) then
              do j= 2, EventFrmNum(3)
                temp(j-1)=      PltData(j,y,i,GrNum)
                tempEvent(j-1,y)= PltEvent(j,y,i,GrNum)
                tempEvent(j-1,x)= PltEvent(j,x,i,GrNum)      
                tempOK(j-1)=    PltDataOK(j,i,GrNum)
              end do ! j  
              k= 1
              do j= EventFrmNum(3), EventFrmNum(5)
                PltData(k,y,i,GrNum)= PltData(j,y,i,GrNum)
                PltDataOK(k,i,GrNum)= PltDataOK(j,i,GrNum)
                PltEvent(k,y,i,GrNum)= PltEvent(j,y,i,GrNum)
                PltEvent(k,x,i,GrNum)= PltEvent(j,x,i,GrNum)
                k= k + 1
              end do ! j
              do j= 1, EventFrmNum(3)-1
                PltData(k,y,i,GrNum)= temp(j)
                PltDataOK(k,i,GrNum)= tempOK(j)
                PltEvent(k,y,i,GrNum)= tempEvent(j,y)
                PltEvent(k,x,i,GrNum)= tempEvent(j,x)
                k  = k + 1  
              end do ! j                  
            end if ! data is from the side to be swapped    
          end if ! NoAlignSides is not true for this plot ...
        end do ! i
      end if ! check for aligning sides
c                       
c     Sort through data and determine x and y min and max
c
      do i= x, y
        DataMin(i)= PD(1,GrNum).Min(i)
        DataMax(i)= PD(1,GrNum).Max(i)
        do j= 2, NumPlts
          if ( PD(j,GrNum).Min(i) .lt. DataMin(i) ) DataMin(i)= PD(j,GrNum).Min(i)
          if ( PD(j,GrNum).Max(i) .gt. DataMax(i) ) DataMax(i)= PD(j,GrNum).Max(i)
        end do
      end do       
      error= .false.
999   return

1000  write(6,1005) i,PD(i,GrNum).FileNum(x),PD(i,GrNum).FileNum(y)
1005  format(' Error- Data set # ',i2,' contains x axis data from file # ',i1/
     &       '        while the y axis data is from file # ',i1'  Something'/
     &       '        has gone wrong internally during selection of the data')
      error= .true.
      return

1010  write(6,1015) i,DataTypeNames(PD(i,GrNum).DataType(x)),
     &                DataTypeNames(PD(i,GrNum).DataType(y))
1015  format(' Error- Data set # ',i2,' contains ',a10,' data in the x axis'/
     &       '        and ',a10,' data in the y axis and the electrical data'/
     &       '        has not been clipped')
      error= .true.
      return

1020  write(6,1025)
1025  format(' Error- Time data quantity can only be specified for x axis'/
     &       '        of the first data set')
      error= .true.
      return
      
1030  write(6,1035)
1035  format(' Error- Time data quantity can only be specified when the'/
     &       '        graph option is set to use the same x axis quantity'/
     &       '        for each data set')
      error= .true.
      return
                           
1040  write(6,1045)
1045  format(' Error- The align sides option has been set but the plot does not'/
     &       '        contain the same data in the x axis for all the data sets' )
      error= .true.
      return

1050  write(6,1055)
1055  format(' Error- The align sides graph option is set, but the x axis data'/
     &       '        of the data sets is not percent gait cycle as it must be'/
     &       '        for this option to work')
      error= .true.
      return
                                                                               
1060  write(6,1065)
1065  format(' Error- The align sides graph option has been set but the gait'/
     &       '        event data does not contain the proper sequence of events'/
     &       '        to allow this to take place')
      error= .true.
      return

1070  write(6,1075)
1075  format(' Error- The align sides graph option has been set but the gait'/
     &       '        data has not been clipped to a single cycle using the'/
     &       '        option: opt gra cyc on')
      error= .true.
      return
      end   
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function EventOrderOK( GaitEvent,NumFrm,Order,EventFrmNum )
      implicit none

      integer*4 GaitEvent(1),NumFrm,Order,EventFrmNum(5)

      integer*4 EventOrder(5,2),rt,lf,i,y,NumEvent
      logical*4 RtBad,LfBad
                   ! rhs,lto,lhs,rto,rhs  lhs,rto,rhs,lto,lhs
      data EventOrder / 1,4,2,3,1,  2,3,1,4,2 / 
      data rt,lf,y / 1,2,2 /

      RtBad= .false.
      LfBad= .false.
      Order=  0
      EventOrderOK= .false.
      i= 1
      do while ( (GaitEvent(i) .eq. 0) .and. (i .le. NumFrm) )
        i= i + 1
      end do
      if ( i .gt. NumFrm ) return
      NumEvent= 0      
      do while ( (NumEvent .le. 4) .and. (i .le. NumFrm) )
        if ( GaitEvent(i) .ne. 0 ) then
          NumEvent= NumEvent + 1
          EventFrmNum(NumEvent)= i
          if ( GaitEvent(i) .ne. EventOrder(NumEvent,rt) ) RtBad= .true.
          if ( GaitEvent(i) .ne. EventOrder(NumEvent,lf) ) LfBad= .true.
        end if
        i= i + 1
      end do    
      if ( NumEvent .lt. 4 ) return
c
c     This is a check for if the last gaitevent might have gotten clipped
c     off when the data was truncated in ANALYZE and if so then add it back.
c
      if ( (NumEvent .eq. 4) .and. (.not. RtBad) ) then
        EventFrmNum(5)= NumFrm
        GaitEvent(NumFrm)= EventOrder(5,rt)
      else if ( (NumEvent .eq. 4) .and. (.not. LfBad) ) then
        EventFrmNum(5)= NumFrm
        GaitEvent(NumFrm)= EventOrder(5,lf)
      end if
      if ( RtBad .and. LfBad ) return
      if ( .not. RtBad ) Order= rt
      if ( .not. LfBad ) Order= lf
      EventOrderOK= .true.
      return
      end
c                           
c   Copyright (c) 1990 by Dwight Meglan           
c                            
      subroutine AssignMrkData( cn,CMND,VarNum,DefFileNum,
     &                          PlotAxis,PltNum,GrNum,error)
      implicit none
               
      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'
      include 'tel_name.inc'
                                  
      record /CmndLine/    CMND
      integer*4 cn,VarNum,DefFileNum,PlotAxis,PltNum,GrNum
      logical*4 error

      integer*4 FileNum,MrkNum,AxisNum,Start,End,i
      logical*4 GetFileNum,GetMrkNum,GetCsAxisNum
      character MrkText*4
c                            
c     Find the file number, marker number and axis number
c
      error= .true.              
      if ( cn+GrNumPrm(VarNum) .gt. CMND.NumCmnd ) goto 1000 ! error, not enough cmnds
      if ( .not. GetFileNum( CMND.NumOpt(cn),CMND.OptNumOK(1,cn),
     &                       CMND.OptIntVal(1,cn),DefFileNum,
     &                       FileNum )           ) goto 1010 ! error
      if ( .not. GetMrkNum( CMND.Text(1),CMND.CmndStart(cn+1),
     &                      CMND.CmndNumOK(cn+1),CMND.CmndIntVal(cn+1),
     &                      FileNum,MrkNum) ) goto 1020
      if ( .not. GetCsAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1030 ! error
c
c     check whether marker position data is available in file
c
      if ( .not. FD(FileNum).MF.read ) goto 1040
      if ( ((VarNum .eq. MVL_DATA) .or. (VarNum .eq. MAC_DATA)) .and.
     &     (.not. FD(FileNum).MF.VelAcc) ) goto 1050
c                        
c     If Graph option is set to CycleClip, then set data limits accordingly
c
      if ( GROPT(GrNum).CycleClip .and. 
     &     .not. FD(FileNum).CF.GaitEvent ) goto 1070 ! error
      if ( GROPT(GrNum).CycleClip ) then
        Start= FD(FileNum).MP.cycle_first_frm(1)
        End=   FD(FileNum).MP.cycle_last_frm(1)
        PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.cycle_length(1)
        if ( Start .eq. End ) then
          Start= 1
          if ( FD(FileNum).ExcessNumMtnFrm ) then
            End= FD(FileNum).OrigNumMtnFrm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumMtnFrm
          else
            End=   FD(FileNum).MP.num_frm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.num_frm
          end if
        end if
      else
        Start= 1
        if ( FD(FileNum).ExcessNumMtnFrm ) then
          End= FD(FileNum).OrigNumMtnFrm
          PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumMtnFrm
        else
          End=   FD(FileNum).MP.num_frm
          PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.num_frm
        end if
      end if
      if ( End-Start+1 .gt. MAX_PLOT_SIZE ) then ! this check is just a
        End= Start + MAX_PLOT_SIZE - 1           ! precaution...
        write(6,100) PltNum,GrNum,MAX_PLOT_SIZE
100     format(' Warning- Data for plot# ',i2,' graph# ',i1,' has been clipped',
     &         ' at ',i5,' points')
      end if
c
c     Assign the marker data to the PD structure
c
      call ReadFileData( FileNum,VarNum,MrkNum,AxisNum,0,0,Start,End,
     &                   PltData(1,PlotAxis,PltNum,GrNum),
     &                   PltDataOK(1,PltNum,GrNum),error   )
      if ( error ) return
      if ( FD(FileNum).CF.GaitEvent ) then
        do i= Start, End
          PltEvent(i-Start+1,PlotAxis,PltNum,GrNum)= FD(FileNum).GaitEvent(i)
        end do
      else
        do i= 1, PD(PltNum,GrNum).NumPnts
          PltEvent(i,PlotAxis,PltNum,GrNum)= 0
        end do
      end if
c
c     Scale the data and setup the various descriptive quantities
c
      call DataMinMax( PltData(1,PlotAxis,PltNum,GrNum),
     &                 PltDataOK(1,PltNum,GrNum),               
     &                 PD(PltNum,GrNum).NumPnts,  
     &                 PD(PltNum,GrNum).Min(PlotAxis),
     &                 PD(PltNum,GrNum).Max(PlotAxis)     )
      if ( GROPT(GrNum).ManLgndFlg ) then
        PD(PltNum,GrNum).Lgnd(PlotAxis)= GROPT(GrNum).ManLgnd(PltNum)
      else
        PD(PltNum,GrNum).Lgnd(PlotAxis)= '                    '
        PD(PltNum,GrNum).Lgnd(PlotAxis)(1:20)= 
     &    VarNames(VarNum)//' '//FD(FileNum).MP.mrk_name(MrkNum)(1:3)//
     &    ' '//CSAxes(AxisNum)
      end if
      PD(PltNum,GrNum).File(PlotAxis)= FD(FileNum).GP.motion_file
      PD(PltNum,GrNum).FileNum(PlotAxis)= FileNum
      PD(PltNum,GrNum).DataType(PlotAxis)= MTN_DT
      cn= cn + GrNumPrm(VarNum) + 1
      error= .false.             
      return                        
                                       
1000  write(6,1005) VarNames(VarNum),GrNumPrm(VarNum)
1005  format(' Error- Not enough parameters.'/
     &       '       ',a3,' requires',i1', parameters to be graphed.')
      return

1010  write(6,1015) VarNames(VarNum)
1015  format(' Error- Invalid file number in options of ',a3,'.')
      return
                                       
1020  write(6,1025) CMND.Text(1)(CMND.CmndStart(cn+1):CMND.CmndStart(cn+1)+3),
     &              FD(FileNum).MP.num_mrk,
     &              (FD(FileNum).MP.mrk_name(i),i=1,FD(FileNum).MP.num_mrk)
1025  format(' Error- ',a4,' is not a valid marker number/name.'/
     &       '        Valid marker numbers are 1 to ',i2/
     &       '        Valid marker names are : ',10(a4,1x)/3(33x,10(a4,1x)/))
      return

1030  write(6,1035) CMND.CmndText(cn+2)
1035  format(' Error- ',a3,' is not a valid axis name.'/
     &       '        Valid axes are: x y z')
      return

1040  write(6,1045) FD(FileNum).Name                
1045  format(' Error- Marker positions not available in file ',a40)
      return

1050  if ( VarNum .eq. MVL_DATA ) then
        write(6,1055) FD(FileNum).Name                
1055    format(' Error- Marker velocities not available in file ',a40)
      else
        write(6,1060) FD(FileNum).Name                
1060    format(' Error- Marker accelerations not available in file ',a40)
      end if
      return

1070  write(6,1075) GrNum,FileNum,FD(FileNum).Name                
1075  format(' Error- Cycle clip set for marker data in graph # ',i2/
     &       '        However, gait event data not present in file # ',i2/
     &       '        File name: ',a40)
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan                        
c                                 
      subroutine AssignSegData( cn,CMND,VarNum,DefFileNum,
     &                          PlotAxis,PltNum,GrNum,DontNormalize,error)
      implicit none
               
      include 'tel_cons.inc'                  
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'
      include 'tel_name.inc'

      record /CmndLine/    CMND
      integer*4 cn,VarNum,DefFileNum,PlotAxis,PltNum,GrNum
      logical*4 DontNormalize,error

      integer*4 FileNum,SegNum,Start,End,i,j,AxisNum,MrkNum,DistNum,CSType,
     &          CompNum,Side
      logical*4 GetFileNum,GetSegNum,SegVarAvailable,GetCsAxisNum,GetSegMrkNum,
     &          GetMtnAxisNum,GetCSType,GetKECompNum,GetScrewCompNum,
     &          GetMomCompNum,GetAngAxisNum
c                                                         
c     Find the file and segment number
c
      error= .true.
      if ( GrNumPrm(VarNum) .lt. 0 ) goto 1007 ! error, invalid Graph object
      if ( cn+GrNumPrm(VarNum) .gt. CMND.NumCmnd ) goto 1000 ! error, not enough cmnds
      if ( .not. GetFileNum( CMND.NumOpt(cn),CMND.OptNumOK(1,cn),
     &                       CMND.OptIntVal(1,cn),DefFileNum,
     &                       FileNum )          ) then
        if ( (VarNum .ne. SVL_DATA) .and. (VarNum .ne. SAC_DATA) ) then
          goto 1010 ! error
        else
          FileNum= DefFileNum
        end if
      end if
      if ( CMND.CmndText(cn)(1:1) .ne. 'B' ) then ! must have segment name
        if ( .not. GetSegNum(CMND.Text(1),CMND.CmndText(cn+1),
     &                       CMND.CmndStart(cn+1),FileNum,SegNum,Side) ) goto 1020
        PD(PltNum,GrNum).Side(PlotAxis)= Side
      end if                                                      
c                                   
c     Check whether segment quantity is available in FileNum
c
      if ( .not. SegVarAvailable(VarNum,FileNum) ) goto 1050 ! error
c                    
c     If Graph option is set to CycleClip, then set data limits accordingly
c
      if ( GROPT(GrNum).CycleClip .and. 
     &     .not. FD(FileNum).CF.GaitEvent ) goto 2070 ! error
      if ( GROPT(GrNum).CycleClip ) then
        Start= FD(FileNum).MP.cycle_first_frm(1)
        End=   FD(FileNum).MP.cycle_last_frm(1)
        PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.cycle_length(1)
        if ( Start .eq. End ) then
          Start= 1
          if ( FD(FileNum).ExcessNumMtnFrm ) then
            End= FD(FileNum).OrigNumMtnFrm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumMtnFrm
          else
            End=   FD(FileNum).MP.num_frm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.num_frm
          end if
        end if
      else
        Start= 1
        if ( FD(FileNum).ExcessNumMtnFrm ) then
          End= FD(FileNum).OrigNumMtnFrm
          PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumMtnFrm
        else
          End=   FD(FileNum).MP.num_frm
          PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.num_frm
        end if
      end if
      if ( End-Start+1 .gt. MAX_PLOT_SIZE ) then ! this check is just a
        End= Start + MAX_PLOT_SIZE - 1           ! precaution...
        write(6,201) PltNum,GrNum,MAX_PLOT_SIZE
201     format(' Warning- Data for plot# ',i2,' graph# ',i1,' has been clipped',
     &         ' at ',i5,' points')
      end if
c
c     Based upon which segment quantity is to be graphed, assign data
c
      if ( VarNum .eq. SPR_DATA ) then ! SPR- not graphable...
        write(6,100)                                                           
100     format(' Error- Segment PaRameters are not graphable.')
        return

      else if ( VarNum .eq. SPN_DATA ) then ! SPN- Segment center position
        if ( .not. GetCsAxisNum(CMND.CmndText(cn+2),AxisNum) ) then
          cn= cn + 2
          goto 1030 ! error
        end if
        call ReadFileData( FileNum,VarNum,SegNum,AxisNum,cntr,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        
      else if ( VarNum .eq. SMP_DATA ) then ! SMP- Segment marker position
        if ( .not. GetSegMrkNum(CMND.CmndText(cn+2),CMND.CmndNumOK(cn+2), 
     &                          CMND.CmndIntVal(cn+2),FileNum,
     &                          SegNum,MrkNum)                ) goto 1040
        if ( .not. GetCsAxisNum(CMND.CmndText(cn+3),AxisNum) ) then
          cn= cn + 3
          goto 1030 ! error
        end if
        call ReadFileData( FileNum,VarNum,SegNum,AxisNum,MrkNum,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
              
      else if ( VarNum .eq. SMD_DATA ) then ! SMD- Segment intermarker distance
        DistNum= CMND.CmndIntVal(cn+2) 
        if ( (.not. CMND.CmndNumOK(cn+2)) .or. (DistNum .lt. 1) .or.
     &       (DistNum .gt. FD(FileNum).SP(SegNum).num_mrk_dist) ) goto 1060
        call ReadFileData( FileNum,VarNum,SegNum,DistNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
              
      else if ( VarNum .eq. SVL_DATA ) then ! SVL- Segment velocity
        if ( .not. GetMtnAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1070 ! error
        if ( .not. GetCSType( CMND.NumOpt(cn),CMND.OptText(1,cn),CSType) ) then
          CSType= GCS_CST ! GCS
        else
          if ( (CSType .ne. GCS_CST) .and. 
     &         (CSType .ne. LCS_CST)       ) goto 1080 ! error bad CS Type
        end if                                                 
        call ReadFileData( FileNum,VarNum,SegNum,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
              
      else if ( VarNum .eq. SAC_DATA ) then ! SAC- Segment acceleration
        if ( .not. GetMtnAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1070 ! error
        if ( .not. GetCSType(CMND.NumOpt(cn),CMND.OptText(1,cn),CSType) ) then
          CSType= GCS_CST ! GCS
        else
          if ( (CSType .ne. GCS_CST) .and. 
     &         (CSType .ne. LCS_CST)       ) goto 1080 ! error- bad CSType
        end if                                                   
        call ReadFileData( FileNum,VarNum,SegNum,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
              
      else if ( VarNum .eq. SKE_DATA ) then ! SKE- Segment kinetic energy
        if ( .not. GetKECompNum(CMND.CmndText(cn+2),CompNum) ) goto 1090 ! error
        call ReadFileData( FileNum,VarNum,SegNum,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
              
      else if ( VarNum .eq. SPE_DATA ) then ! SPE- Segment potential energy
        call ReadFileData( FileNum,VarNum,SegNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
              
      else if ( VarNum .eq. STE_DATA ) then ! STE- Segment total energy
        call ReadFileData( FileNum,VarNum,SegNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
              
      else if ( VarNum .eq. SIS_DATA ) then ! SIS- Instantaneous kinematic screw
        if ( .not. GetScrewCompNum(CMND.CmndText(cn+2),CompNum) ) goto 1100
        call ReadFileData( FileNum,VarNum,SegNum,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
              
      else if ( VarNum .eq. SFS_DATA ) then ! SFS- Instantaneous kinematic screw
        if ( .not. GetScrewCompNum(CMND.CmndText(cn+2),CompNum) ) goto 1100
        call ReadFileData( FileNum,VarNum,SegNum,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
              
      else if ( VarNum .eq. SMM_DATA ) then ! SMM- Segment momentum
        if ( .not. GetMomCompNum(CMND.CmndText(cn+2),CompNum) ) then
          cn= cn + 2
          goto 1110 ! error         
        end if
        call ReadFileData( FileNum,VarNum,SegNum,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
              
      else if ( VarNum .eq. SAN_DATA ) then ! SAN- Segment angle to GCS
        if ( .not. GetAngAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1120 ! error
        call ReadFileData( FileNum,VarNum,SegNum,AxisNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
                        
      else if ( VarNum .eq. BKE_DATA ) then ! BKE- Body kinetic energy
        if ( .not. GetKECompNum(CMND.CmndText(cn+1),CompNum) ) then
          cn= cn + 2
          goto 1090 ! error         
        end if
        call ReadFileData( FileNum,VarNum,CompNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return                
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
              
      else if ( VarNum .eq. BPE_DATA ) then ! BPE- Body potential energy
        call ReadFileData( FileNum,VarNum,0,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
        
      else if ( VarNum .eq. BTE_DATA ) then ! BTE- Body total energy
        call ReadFileData( FileNum,VarNum,0,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return

      else if ( VarNum .eq. BCM_DATA ) then ! BCM- Body center of mass
        if ( .not. GetCsAxisNum(CMND.CmndText(cn+1),AxisNum) ) then
          cn= cn + 1                
          goto 1030 ! error
        end if
        call ReadFileData( FileNum,VarNum,AxisNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return

      else if ( VarNum .eq. BCV_DATA ) then ! BCM- Body center of mass Vel
        if ( .not. GetCsAxisNum(CMND.CmndText(cn+1),AxisNum) ) then
          cn= cn + 1                
          goto 1030 ! error
        end if
        call ReadFileData( FileNum,VarNum,AxisNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return

      else if ( VarNum .eq. BMM_DATA ) then ! BMM- Body momentum
        if ( .not. GetMomCompNum(CMND.CmndText(cn+1),CompNum) ) then
          cn= cn + 1
          goto 1110 ! error         
        end if
        call ReadFileData( FileNum,VarNum,CompNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
                                                   
      end if                        
c           
c     Assign GaitEvents
c
      if ( FD(FileNum).CF.GaitEvent ) then
        do i= Start, End
          PltEvent(i-Start+1,PlotAxis,PltNum,GrNum)= FD(FileNum).GaitEvent(i)
        end do
      else
        do i= 1, PD(PltNum,GrNum).NumPnts
          PltEvent(i,PlotAxis,PltNum,GrNum)= 0
        end do
      end if
c
c    Finish up now that the proper quantity has been found and the data assigned
c                                        
      call DataMinMax( PltData(1,PlotAxis,PltNum,GrNum),
     &                 PltDataOK(1,PltNum,GrNum),
     &                 PD(PltNum,GrNum).NumPnts,  
     &                 PD(PltNum,GrNum).Min(PlotAxis),
     &                 PD(PltNum,GrNum).Max(PlotAxis)     )

      if ( GROPT(GrNum).ManLgndFlg ) then
        PD(PltNum,GrNum).Lgnd(PlotAxis)= GROPT(GrNum).ManLgnd(PltNum)
      else
        PD(PltNum,GrNum).Lgnd(PlotAxis)= '                    '
        PD(PltNum,GrNum).Lgnd(PlotAxis)(1:3)= CMND.CmndText(cn)//' '
        j= 5             
        do i= 1, GrNumPrm(VarNum)
          PD(PltNum,GrNum).Lgnd(PlotAxis)= 
     &      PD(PltNum,GrNum).Lgnd(PlotAxis)(j:j+3)//CMND.CmndText(cn+i)//' '
          j= j + 4
        end do
      end if
      PD(PltNum,GrNum).File(PlotAxis)= FD(FileNum).GP.motion_file
      PD(PltNum,GrNum).FileNum(PlotAxis)= FileNum        
      PD(PltNum,GrNum).DataType(PlotAxis)= MTN_DT
      cn= cn + GrNumPrm(VarNum) + 1
      error= .false.             
      return
                       
1000  write(6,1005) VarNames(VarNum),GrNumPrm(VarNum)
1005  format(' Error- Not enough parameters.'/
     &       '       ',a3,' requires',i1', parameters to be graphed.')
      return

1007  write(6,1009) VarNames(VarNum)
1009  format(' Error- ',a3,' is an invalid segment quantity for graphing')
      return
                                       
1010  write(6,1015) VarNames(VarNum)
1015  format(' Error- Invalid file number in options of ',a3,'.')
      return
            
1020  write(6,1025) CMND.CmndText(cn+1)
1025  format(' Error- ',a3,' is not a valid segment name.')
      return
 
1030  write(6,1035) CMND.CmndText(cn)
1035  format(' Error- ',a3,' is not a valid axis name.')
      return                                                              

1040  write(6,1045) CMND.CmndText(cn+2),SegNames(SegNum),
     &              (FD(FileNum).SP(SegNum).mrk_num(i),
     &               i=1,FD(FileNum).SP(SegNum).num_mrk)
1045  format(' Error- ',a3,' is not a valid marker for ',a4/
     &       '        Valid marker #''s are ',5i3)
      return
      
1050  write(6,1055) VarNames(VarNum),FD(FileNum).Name
1055  format(' Error- ',a3,' is not available in ',a40)
      return
            
1060  write(6,1065) CMND.CmndText(cn+2),SegNames(SegNum),
     &              FD(FileNum).SP(SegNum).num_mrk_dist
1065  format(' Error- ',a3,' is not a valid intermarker distance number',
     &       ' for ',a4/
     &       '        Valid distance #''s are from 1 to ',i2)
      return

1070  write(6,1075) CMND.CmndText(cn+2)
1075  format(' Error- ',a3,' is not a valid motion axis name')
      return

1080  write(6,1085) VarNames(VarNum)
1085  format(' Error- Options for ',a3,' contain an invalid'/
     &       '        coordinate system name')
      return

1090  write(6,1095) CMND.CmndText(cn)
1095  format(' Error- ',a3,' is not a valid kinetic energy component'/
     &       '        Valid components are: ROT TRA TOT')
      error= .true.
      return

1100  write(6,1105) CMND.CmndText(cn+2),(ScrewCompNames(i),i=1,8)
1105  format(' Error- ',a3,' is an invalid kinematic screw component'/
     &       '        Valid components are : ',8(a3,1x))
      return

1110  write(6,1115) CMND.CmndText(cn),(MomCompNames(i),i=1,8)
1115  format(' Error- ',a3,' is not a valid momentum component'/
     &       '        Valid components are : ',8(a3,1x))
      return

1120  write(6,1125) CMND.CmndText(cn+2),(AngAxes(i),i=1,3)
1125  format(' Error- ',a3,' is an invalid angle axis name'/
     &       '        Valid names are : ',3(a3,1x))
      return

2070  write(6,2075) GrNum,FileNum,FD(FileNum).Name                
2075  format(' Error- Cycle clip set for segment data in graph # ',i2/
     &       '        However, gait event data not present in file # ',i2/
     &       '        File name: ',a40)
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c                         
      subroutine AssignJntData( cn,CMND,VarNum,DefFileNum,
     &                          PlotAxis,PltNum,GrNum,DontNormalize,error )
      implicit none
               
      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'
      include 'tel_name.inc'
                          
      record /CmndLine/    CMND
      integer*4 cn,VarNum,DefFileNum,PlotAxis,PltNum,GrNum
      logical*4 error,DontNormalize

      real*4    CycleTime                             
      integer*4 FileNum,JntNum,side,CSType,Start,End,AxisNum,i,j,CompNum
      logical*4 LegSum,GetFileNum,GetJntNum,GetCSType,JntVarAvailable,
     &          GetAngAxisNum,GetFrcAxisNum,GetWrenchCompNum,GetScrewCompNum,
     &          GetJCSFrcAxisNum,resultOK,NormVelAcc,GetPowerCompNum,
     &          GetTransCompNum,GetCsAxisNum,GetSide,GetPACompNum
      
c                
c     Find the file and joint number, also coordinate system if applicable
c
      error= .true.
      NormVelAcc= .false.
      if ( cn+GrNumPrm(VarNum) .gt. CMND.NumCmnd ) goto 1000 ! error, not enough cmnds
      CSType= JCS_CST
      if ( (VarNum .eq. JMA_DATA) .or. (VarNum .eq. JWA_DATA) ) CSType= PRO_CST
      do i= 1, CMND.NumOpt(cn)
        if ( CMND.OptNumOK(i,cn) ) then 
          resultOK= GetFileNum( CMND.NumOpt(cn),CMND.OptNumOK(i,cn),
     &                          CMND.OptIntVal(i,cn),DefFileNum,FileNum )
          if ( .not. resultOK ) goto 1010 ! error in file number
        else if ( (VarNum .ge. JAN_DATA) .and. 
     &            (VarNum .le. JAC_DATA)       ) then ! JAN, JVL, or JAC
          if ( .not. GetCSType(CMND.NumOpt(cn),CMND.OptText(i,cn),CSType) )
     &      CSType= JCS_CST ! JCS ! default coord system
          if ( (CSType .ne. JCS_CST) .and. (CSType .ne. EUL_CST) ) goto 1030 ! error
          if ( CMND.OptText(i,cn) .eq. 'NOR' ) NormVelAcc= .true.
        else if ( (VarNum .eq. JLD_DATA) .or. (VarNum .eq. JLL_DATA) .or.
     &            (VarNum .eq. JTR_DATA)                                  ) then
          if ( .not. GetCSType(CMND.NumOpt(cn),CMND.OptText(i,cn),CSType) )
     &      CSType= JCS_CST ! JCS ! default coord system
          if ( (CSType .eq. LCS_CST) .or. (CSType .eq. EUL_CST) ) goto 1060 ! error
        else if ( VarNum .eq. JSA_DATA ) then
          if ( .not. GetCSType(CMND.NumOpt(cn),CMND.OptText(i,cn),CSType) )
     &      CSType= JCS_CST ! JCS ! default coord system
          if ( (CSType .eq. LCS_CST) .or. (CSType .eq. EUL_CST) .or.
     &         (CSType .eq. GCS_CST)        ) goto 1160 ! error
        else if ( (VarNum .eq. JMA_DATA) .or. 
     &            (VarNum .eq. JWA_DATA)      ) then
          if ( .not. GetCSType(CMND.NumOpt(cn),CMND.OptText(i,cn),CSType) )
     &      CSType= PRO_CST ! Prox LCS default coord system
          if ( (CSType .eq. LCS_CST) .or. (CSType .ge. JCS_CST) .or.
     &         (CSType .eq. EUL_CST)        ) goto 1210
        else
          goto 1120 ! invalid option
        end if
      end do
      if ( (FileNum .le. 0) .or. (FileNum .gt. NumFileOpen) ) FileNum= DefFileNum
      if ( NormVelAcc ) then ! calculate the Cycle Time
        if ( FD(FileNum).MP.cycle_length(1) .lt. 1.0e-05 ) goto 1130
        if ( FD(FileNum).rMtnFrmRate .lt. 1.0e-5 ) goto 1140
        CycleTime= FD(FileNum).MP.cycle_length(1)/FD(FileNum).rMtnFrmRate
      end if
      if ( (VarNum .ne. JLL_DATA) .and. (VarNum .ne. JPL_DATA) ) then
        if ( .not. GetJntNum(CMND.Text(1),CMND.CmndText(cn+1),
     &                       CMND.CmndStart(cn+1),FileNum,JntNum,Side) ) goto 1020
        PD(PltNum,GrNum).Side(PlotAxis)= Side
      else ! leg summed quantity- find side
        if ( .not. GetSide( CMND.CmndText(cn+1),side ) ) goto 1027 ! error
        PD(PltNum,GrNum).Side(PlotAxis)= Side
      end if 
c     
c     Check whether joint quantity is available in FileNum
c
      if ( .not. JntVarAvailable(VarNum,CSType,FileNum) ) goto 1040 ! error
c                    
c     If Graph option is set to CycleClip, then set data limits accordingly
c
      if ( GROPT(GrNum).CycleClip .and. 
     &     .not. FD(FileNum).CF.GaitEvent ) goto 2070 ! error
      if ( GROPT(GrNum).CycleClip ) then
        Start= FD(FileNum).MP.cycle_first_frm(1)
        End=   FD(FileNum).MP.cycle_last_frm(1)
        PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.cycle_length(1)
        if ( Start .eq. End ) then
          Start= 1
          if ( FD(FileNum).ExcessNumMtnFrm ) then
            End= FD(FileNum).OrigNumMtnFrm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumMtnFrm
          else
            End=   FD(FileNum).MP.num_frm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.num_frm
          end if
        end if
      else
        Start= 1
        if ( FD(FileNum).ExcessNumMtnFrm ) then
          End= FD(FileNum).OrigNumMtnFrm
          PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumMtnFrm
        else
          End=   FD(FileNum).MP.num_frm
          PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.num_frm
        end if
      end if
      if ( End-Start+1 .gt. MAX_PLOT_SIZE ) then ! this check is just a
        End= Start + MAX_PLOT_SIZE - 1           ! precaution...
        write(6,100) PltNum,GrNum,MAX_PLOT_SIZE
100     format(' Warning- Data for plot# ',i2,' graph# ',i1,' has been clipped',
     &         ' at ',i5,' points')
      end if
c
c     Based upon which joint quantity is to be graphed, assign data
c                          
      if ( VarNum .eq. JAN_DATA ) then ! JAN- joint angle
        if ( .not. GetAngAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1050 ! error
        call ReadFileData( FileNum,VarNum,JntNum,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( (CSType .eq. JCS_CST) .and. 
     &       GROPT(GrNum).RemAvgAng .and. 
     &       FD(FileNum).AF.AngJCS        ) then
          do i= 1, PD(PltNum,GrNum).NumPnts
            PltData(i,PlotAxis,PltNum,GrNum)= 
     &                             PltData(i,PlotAxis,PltNum,GrNum) -
     &                             FD(FileNum).AvgJntAngJCS(AxisNum,JntNum)
          end do                          
        else if ( (CSType .eq. EUL_CST) .and. 
     &            GROPT(GrNum).RemAvgAng .and. 
     &            FD(FileNum).AF.AngEUL        ) then
          do i= 1, PD(PltNum,GrNum).NumPnts
            PltData(i,PlotAxis,PltNum,GrNum)=               
     &                           PltData(i,PlotAxis,PltNum,GrNum) -
     &                           FD(FileNum).AvgJntAngEUL(AxisNum,JntNum)
          end do
        end if
                                                               
      else if ( VarNum .eq. JVL_DATA ) then ! JVL- joint velocity
        if ( .not. GetAngAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1050 ! error
        call ReadFileData( FileNum,VarNum,JntNum,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( NormVelAcc ) then
          do i= 1, PD(PltNum,GrNum).NumPnts
            PltData(i,PlotAxis,PltNum,GrNum)= PltData(i,PlotAxis,PltNum,GrNum)/
     &                                        CycleTime
          end do
        end if
                                                               
      else if ( VarNum .eq. JAC_DATA ) then ! JAC- joint acceleration
        if ( .not. GetAngAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1050 ! error
        call ReadFileData( FileNum,VarNum,JntNum,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( NormVelAcc ) then
          CycleTime= CycleTime**2
          do i= 1, PD(PltNum,GrNum).NumPnts
            PltData(i,PlotAxis,PltNum,GrNum)= PltData(i,PlotAxis,PltNum,GrNum)/
     &                                        CycleTime
          end do
        end if
                                    
      else if ( VarNum .eq. JLD_DATA ) then ! JLD- joint load
        if ( CSType .ne. JCS_CST ) then
          if ( .not. GetFrcAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1080 ! error
        else
          if ( .not. GetJCSFrcAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1110
        end if
        call ReadFileData( FileNum,VarNum,JntNum,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
        
      else if ( VarNum .eq. JLL_DATA ) then ! JLL- joint load
        if ( .not. GetCSType(CMND.NumOpt(cn),CMND.OptText(1,cn),CSType) ) then
          CSType= JCS_CST ! JCS              
        else if ( (CSType .ne. GCS_CST) .and. (CSType .ne. JCS_CST) ) then
          goto 1070 ! error
        end if
        if ( CSType .ne. JCS_CST ) then
          if ( .not. GetFrcAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1080 ! error
        else
          if ( .not. GetJCSFrcAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1110
          if ( AxisNum .gt. mz ) goto 1150 ! error- invalid here...
        end if
        call ReadFileData( FileNum,VarNum,side,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
        
      else if ( VarNum .eq. JWR_DATA ) then ! JWR- joint wrench
        if ( .not. GetWrenchCompNum( CMND.CmndText(cn+2),CompNum) ) goto 1090 ! error
        call ReadFileData( FileNum,VarNum,JntNum,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
c        if ( GROPT(GrNum).NormWt .or. GROPT(GrNum).NormWtHt ) 
c     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
c        if ( error ) return
                                                                               
      else if ( VarNum .eq. JPW_DATA ) then ! JPW- joint power
        if (.not. GetPowerCompNum(CMND.CmndText(cn+2),CompNum) ) goto 1170 ! error
        call ReadFileData( FileNum,VarNum,JntNum,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
                  
      else if ( VarNum .eq. JPL_DATA ) then ! JPL- joint power
        if (.not. GetPowerCompNum(CMND.CmndText(cn+2),CompNum) ) goto 1170 ! error
        call ReadFileData( FileNum,VarNum,Side,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
                  
      else if ( VarNum .eq. JIS_DATA ) then ! JIS- Joint instantaneous kinematic screw
        if ( .not. GetScrewCompNum(CMND.CmndText(cn+2),CompNum) ) goto 1100
        call ReadFileData( FileNum,VarNum,JntNum,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
                                                     
      else if ( VarNum .eq. JFS_DATA ) then ! JFS- Joint finite kinematic screw
        if ( .not. GetScrewCompNum(CMND.CmndText(cn+2),CompNum) ) goto 1100
        call ReadFileData( FileNum,VarNum,JntNum,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        
      else if ( VarNum .eq. JTR_DATA ) then ! JTR- joint translation
        if ( .not. GetTransCompNum(CMND.CmndText(cn+2),CSType,AxisNum) ) 
     &    goto 1180 ! error
        call ReadFileData( FileNum,VarNum,JntNum,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return                          

      else if ( VarNum .eq. JSA_DATA ) then ! JSA- joint screw angle
        if ( CSType .eq. JCS_CST ) then
          if ( .not. GetAngAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1190
        else
          if ( .not. GetCsAxisNum(CMND.CmndText(cn+2),AxisNum) ) goto 1200
        end if
        call ReadFileData( FileNum,VarNum,JntNum,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return

      else if ( VarNum .eq. JMA_DATA ) then ! JMA- joint moment arm
        if ( .not. GetPACompNum(CMND.CmndText(cn+2),CSType,CompNum) ) then
          cn= cn + 2
          goto 1220 ! error
        end if
        call ReadFileData( FileNum,VarNum,JntNum,CompNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return

      else if ( VarNum .eq. JWA_DATA ) then ! JWA- joint wrench arm
        if ( .not. GetPACompNum(CMND.CmndText(cn+2),CSType,CompNum) ) then
          cn= cn + 2
          goto 1220 ! error
        end if
        call ReadFileData( FileNum,VarNum,JntNum,CompNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return

      end if                        
c
c     Assign GaitEvents
c
      if ( FD(FileNum).CF.GaitEvent ) then
        do i= Start, End
          PltEvent(i-Start+1,PlotAxis,PltNum,GrNum)= FD(FileNum).GaitEvent(i)
        end do
      else
        do i= 1, PD(PltNum,GrNum).NumPnts
          PltEvent(i,PlotAxis,PltNum,GrNum)= 0
        end do
      end if
c
c    Finish up now that the proper quantity has been found and the data assigned
c
      call DataMinMax( PltData(1,PlotAxis,PltNum,GrNum),
     &                 PltDataOK(1,PltNum,GrNum),
     &                 PD(PltNum,GrNum).NumPnts,  
     &                 PD(PltNum,GrNum).Min(PlotAxis),
     &                 PD(PltNum,GrNum).Max(PlotAxis)     )
      if ( GROPT(GrNum).ManLgndFlg ) then
        PD(PltNum,GrNum).Lgnd(PlotAxis)= GROPT(GrNum).ManLgnd(PltNum)
      else
        PD(PltNum,GrNum).Lgnd(PlotAxis)= '                    '
        PD(PltNum,GrNum).Lgnd(PlotAxis)(1:3)= CMND.CmndText(cn)//' '
        j= 5             
        do i= 1, GrNumPrm(VarNum)
          PD(PltNum,GrNum).Lgnd(PlotAxis)= PD(PltNum,GrNum).Lgnd(PlotAxis)(1:j)//
     &                                     CMND.CmndText(cn+i)//' '
          j= j + 4
        end do
      end if
      PD(PltNum,GrNum).File(PlotAxis)= FD(FileNum).GP.motion_file
      PD(PltNum,GrNum).FileNum(PlotAxis)= FileNum
      PD(PltNum,GrNum).DataType(PlotAxis)= MTN_DT
      cn= cn + GrNumPrm(VarNum) + 1
      error= .false.             
      return
                       
1000  write(6,1005) VarNames(VarNum),GrNumPrm(VarNum)
1005  format(' Error- Not enough parameters.'/
     &       '       ',a3,' requires',i1', parameters to be graphed.')
      return

1010  write(6,1015) VarNames(VarNum)
1015  format(' Error- Invalid file number in options of ',a3,'.')
      return
            
1020  write(6,1025) CMND.CmndText(cn+1),(JntNames(i),i=1,MAX_JNT)
1025  format(' Error- ',a3,' is not a valid joint name.'/
     &       '        Valid Joint Names are: ',5(a4,1x)/
     &       2(32x,5(a3,1x)/) )
      return
 
1027  write(6,1029) CMND.CmndText(cn+1)
1029  format(' Error- ',a3,' is not a valid side name.'/
     &       '        Valid side names are: rt lf')
      return
                               
1030  write(6,1035) VarNames(VarNum)
1035  format(' Error- Invalid coordinate system in options for ',a3/
     &       '        Only [JCS]/EULer are allowed')
      return
                    
1040  write(6,1045) VarNames(VarNum),FD(FileNum).Name
1045  format(' Error- ',a3,' is not available in file ',a40)
      return                        

1050  write(6,1055) CMND.CmndText(cn+2),(AngAxes(i),i=1,3)
1055  format(' Error- ',a3,' is an invalid angle axis name'/
     &       '        Valid axis names are: ',3(a3,1x))   
      return        
                 
1060  write(6,1065) VarNames(VarNum)
1065  format(' Error- Invalid coordinate system in options for ',a3/
     &       '        Only GCS/[JCS]/PROximal/DIStal are allowed')
      return
                    
1070  write(6,1075) VarNames(VarNum)
1075  format(' Error- Invalid coordinate system in options for ',a3/
     &       '        Only GCS/[JCS] are allowed')
      return                                      
                    
1080  write(6,1085) CMND.CmndText(cn+2),(FrcNames(i),i=1,6)
1085  format(' Error- ',a3,' is an invalid load axis name'/
     &       '        Valid load names are: ',6(a3,1x) )
      return      

1090  write(6,1095) CMND.CmndText(cn+2),(WrenchCompNames(i),i=1,8)
1095  format(' Error- ',a3,' is an invalid load wrench component'/
     &       '        Valid Components are: ',8(a3,1x) )
      return                           

1100  write(6,1105) CMND.CmndText(cn+2),(ScrewCompNames(i),i=1,8)
1105  format(' Error- ',a3,' is an invalid kinematic screw component'/
     &       '        Valid components are: ',8(a3,1x) )
      return                                              

1110  write(6,1115) CMND.CmndText(cn+2),(JCSFrcNames(i),i=1,6)
1115  format(' Error- ',a3,' is an invalid JCSload axis name'/
     &       '        Valid JCS load names are: ',6(a3,1x) )
      return      

1120  write(6,1125) CMND.OptText(i,cn),CMND.CmndText(cn),NumFileOpen
1125  format(' Error- ',a3,' is an invalid option for ',a3/
     &       '        Valid options are: File #''s 1 to ',i1/
     &       '                           JCS EUL NOR')
      return

1130  write(6,1135)
1135  format(' Error- Cycle length is <= 0'/
     &       '        To normalize joint velocity and acceleration it must > 0')
      return

1140  write(6,1145)
1145  format(' Error- Motion data frame rate is <= 0 frames/sec'/
     &       '        To normalize joint velocity and acceleration it must > 0')
      return

1150  write(6,1155) (JCSFrcNames(i),i=1,6)
1155  format(' Error- The JCS load quantities MOM & FRC are not valid for'/
     &       '        the summed leg joint loads'/
     &       '        Valid loads are: ',6(1x,a3))
      return

1160  write(6,1165) VarNames(VarNum)
1165  format(' Error- Invalid coordinate system in options for ',a3/
     &       '        Only [JCS]/PROximal/DIStal are allowed')
      return

1170  write(6,1175) CMND.CmndText(cn+2),(PowerCompNames(i),i=1,4)
1175  format(' Error- ',a3,' is an invalid joint power component'/
     &       '        Valid Components are: ',4(a3,1x) )
      return                           

1180  if ( CSType .eq. JCS_CST ) then
        write(6,1185) CMND.CmndText(cn+2),(JCSTransCompNames(i),i=1,4)
      else
        write(6,1185) CMND.CmndText(cn+2),(TransCompNames(i),i=1,4)
      end if
1185  format(' Error- ',a3,' is an invalid joint translation component'/
     &       '        Valid Components are: ',4(a3,1x) )
      return                           

1190  write(6,1195) CMND.CmndText(cn+2),(AngAxes(i),i=1,3)
1195  format(' Error- ',a3,' is an invalid JCS joint screw component'/
     &       '        Valid Components are: ',3(a3,1x) )
      return                           

1200  write(6,1205) CMND.CmndText(cn+2),(CSAxes(i),i=1,3)
1205  format(' Error- ',a3,' is an invalid LCS joint screw component'/
     &       '        Valid Components are: ',3(a3,1x) )
      return                           

1210  write(6,1215) VarNames(VarNum)
1215  format(' Error- Invalid coordinate system in options for ',a3/
     &       '        Only [PROximal]/DIStal/GCS are allowed')
      return

1220  j= 3
      if ( CSType .eq. GCS_CST ) j= 4
      write(6,1225) CMND.CmndText(cn),(PitArmCompNames(i),i=1,j)
1225  format(' Error- ',a3,' is not a valid moment/wrench arm component.'/
     &       '        Valid names are: ',4(a3,1x) )
      return

2070  write(6,2075) GrNum,FileNum,FD(FileNum).Name                
2075  format(' Error- Cycle clip set for joint data in graph # ',i2/
     &       '        However, gait event data not present in file # ',i2/
     &       '        File name: ',a40)
      return
      end                                                 
c                                                       
c   Copyright (c) 1990 by Dwight Meglan
c                   
      subroutine AssignFrcData( cn,CMND,VarNum,DefFileNum,
     &                          PlotAxis,PlotNum,GrNum,DontNormalize,error )
      implicit none
               
      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'
      include 'tel_name.inc'
                          
      record /CmndLine/    CMND
      integer*4 cn,VarNum,DefFileNum,PlotAxis,PlotNum,GrNum
      logical*4 error,DontNormalize
      
      integer*4 FileNum,CSType,Start,End,side,AxisNum,i,j,PltNum,CompNum,frm
      logical*4 GetFileNum,GetCSType,FrcVarAvailable,GetSide,GetFrcAxisNum,
     &          GetCSAxisNum,GetWrenchCompNum,GetImpCompNum,resultOK,
     &          EventAssigned,GetPACompNum
c
c     Find the file number and check whether force variable is available
c                
      error= .true.
      if ( cn+GrNumPrm(VarNum) .gt. CMND.NumCmnd ) goto 1000 ! error, not enough cmnds
      CSType= GCS_CST
      do i= 1, CMND.NumOpt(cn)
        if ( CMND.OptNumOK(i,cn) ) then
          resultOK= GetFileNum( CMND.NumOpt(cn),CMND.OptNumOK(i,cn),
     &                          CMND.OptIntVal(i,cn),DefFileNum,FileNum )
          if ( .not. resultOK ) goto 1010 ! error in file #
        else if ( VarNum .eq. FCF_DATA ) then ! check for CSType
          if ( .not. GetCSType(CMND.NumOpt(cn),CMND.OptText(i,cn),CSType) )
     &       CSType= GCS_CST ! GCS
          if ( CSType .gt. LCS_CST ) goto 1020 ! error, bad CS type
        else if ( VarNum .eq. FFT_DATA ) then ! check for CSType
          if ( .not. GetCSType(CMND.NumOpt(cn),CMND.OptText(i,cn),CSType) )
     &       CSType= GCS_CST ! GCS
          if ( CSType .gt. LCS_CST ) goto 1020 ! error, bad CS type
        else if ( (VarNum .eq. PMA_DATA) .or.
     &            (VarNum .eq. PWA_DATA)      ) then ! check for CSType
          if ( .not. GetCSType(CMND.NumOpt(cn),CMND.OptText(i,cn),CSType) )
     &       CSType= GCS_CST ! GCS
          if ( (CSType .gt. GCS_CST) .and.
     &         (CSType .lt. PLV_CST)       ) goto 1110 ! error, bad CS type
        else
          goto 1100 ! error in option 
        end if
      end do ! i
      if ( (FileNum .le. 0) .or. (FileNum .gt. NumFileOpen) ) FileNum= DefFileNum
      if ( .not. FrcVarAvailable(VarNum,CSType,FileNum) ) goto 1030 ! error
c                         
c     Find foot or plate number depending upon variable                   
c           
      if ( (VarNum .eq. FFT_DATA) .or. 
     &     (VarNum .eq. FCF_DATA) .or.     
     &     (VarNum .eq. FWF_DATA) .or.
     &     (VarNum .eq. FCV_DATA) .or.
     &     (VarNum .eq. FF1_DATA) .or.
     &     (VarNum .eq. FF2_DATA)      ) then ! individual foot data
        if ( .not. GetSide( CMND.CmndText(cn+1),side ) ) goto 1040 ! error
      else if ( (VarNum .eq. FPL_DATA) .or. 
     &          (VarNum .eq. FCP_DATA) .or.       
     &          (VarNum .eq. FWP_DATA) .or. 
     &          (VarNum .eq. FP1_DATA) .or. 
     &          (VarNum .eq. FP2_DATA)      ) then ! individual plate data
        if ( (CMND.CmndIntVal(cn+1) .gt. FD(FileNum).FP.num_plt) .or.
     &       (CMND.CmndIntVal(cn+1) .lt. 1)                    ) then
          goto 1050 ! error, bad plate number
        else    
          PltNum= CMND.CmndIntVal(cn+1)
        end if
      end if                    
c                                            
c     If Graph option is set to CycleClip, then set data limits accordingly
c               
      if ( GROPT(GrNum).CycleClip .and. 
     &     .not. FD(FileNum).CF.GaitEvent ) goto 2070 ! error
      if ( GROPT(GrNum).CycleClip ) then
        if ( FD(FileNum).FF.IndFt ) then
          Start= 1
          End=   FD(FileNum).MP.cycle_length(1)
          PD(PlotNum,GrNum).NumPnts= FD(FileNum).MP.cycle_length(1)
        else
          Start= FD(FileNum).FP.first_frm
          End=   FD(FileNum).FP.last_frm    
          PD(PlotNum,GrNum).NumPnts= End - Start + 1
        end if
      else
        Start= 1                     
        if ( FD(FileNum).ExcessNumFrcFrm ) then
          End= FD(FileNum).OrigNumFrcFrm
          PD(PlotNum,GrNum).NumPnts= FD(FileNum).OrigNumFrcFrm
        else
          End=   FD(FileNum).FP.num_frm
          PD(PlotNum,GrNum).NumPnts= FD(FileNum).FP.num_frm
        end if
      end if
      if ( End-Start+1 .gt. MAX_PLOT_SIZE ) then ! this check is just a
        End= Start + MAX_PLOT_SIZE - 1           ! precaution...
        write(6,100) PlotNum,GrNum,MAX_PLOT_SIZE
100     format(' Warning- Data for plot# ',i2,' graph# ',i1,' has been clipped',
     &         ' at ',i5,' points')
      end if
c                                                            
c     Based upon which force variable in to be graphed, assign data
c                                     
      if ( VarNum .eq. FPL_DATA ) then ! FPL- Force plate data  
        if ( .not. GetFrcAxisNum(CMND.CmndText(cn+2),AxisNum) ) then
          cn= cn + 2
          goto 1060 ! error
        end if
        call ReadFileData( FileNum,VarNum,PltNum,AxisNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return                                
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PlotNum,GrNum,FileNum,error )
        if ( error ) return
        if ( GROPT(GrNum).PositiveFz .and. (AxisNum .eq. fz) ) then
          do i= 1, PD(PlotNum,GrNum).NumPnts
            PltData(i,PlotAxis,PlotNum,GrNum)= -PltData(i,PlotAxis,PlotNum,GrNum)
          end do
        end if

      else if ( VarNum .eq. FFT_DATA ) then ! FFT- Ind Foot force data
        if ( .not. GetFrcAxisNum(CMND.CmndText(cn+2),AxisNum) ) then
          cn= cn + 2       
          goto 1060 ! error
        end if
        call ReadFileData( FileNum,VarNum,side,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PlotNum,GrNum,FileNum,error )
        if ( error ) return
        if ( GROPT(GrNum).PositiveFz .and. (AxisNum .eq. fz) ) then
          do i= 1, PD(PlotNum,GrNum).NumPnts
            PltData(i,PlotAxis,PlotNum,GrNum)= -PltData(i,PlotAxis,PlotNum,GrNum)
          end do
        end if
                                    
      else if ( VarNum .eq. FCB_DATA ) then ! FCB- Combined force plate data
        if ( .not. GetFrcAxisNum(CMND.CmndText(cn+1),AxisNum) ) then
          cn= cn + 1                             
          goto 1060 ! error
        end if
        call ReadFileData( FileNum,VarNum,AxisNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return               
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PlotNum,GrNum,FileNum,error )
        if ( error ) return
        if ( GROPT(GrNum).PositiveFz .and. (AxisNum .eq. fz) ) then
          do i= 1, PD(PlotNum,GrNum).NumPnts
            PltData(i,PlotAxis,PlotNum,GrNum)= -PltData(i,PlotAxis,PlotNum,GrNum)
          end do
        end if
                                              
      else if ( VarNum .eq. FCP_DATA ) then ! FCP- Force plate data cntr pressure
        if ( .not. GetCSAxisNum(CMND.CmndText(cn+2),AxisNum) ) then
          cn= cn + 2
          goto 1070 ! error
        end if
        call ReadFileData( FileNum,VarNum,PltNum,AxisNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return
        if ( GROPT(GrNum).ShowFpOutline ) GD(GrNum).ShowFpOutline= .true.
                                                            
      else if ( VarNum .eq. FCF_DATA ) then ! FCF- Ind Foot force data cntr pressure
        if ( .not. GetCSAxisNum(CMND.CmndText(cn+2),AxisNum) ) then
          cn= cn + 2
          goto 1070 ! error 
        end if              
        call ReadFileData( FileNum,VarNum,side,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return
        if ( GROPT(GrNum).ShowFpOutline ) GD(GrNum).ShowFpOutline= .true.
        if ( GROPT(GrNum).ShowFtOutLine ) then
          GD(GrNum).ShowFtOutLine(side)= .true.
          GD(GrNum).FtFileNum(side)= FileNum
          GD(GrNum).FtPltNum(side)= PlotNum
          GD(GrNum).FtOutLineGCS= .false.
          if ( CSType .eq. GCS_CST ) GD(GrNum).FtOutLineGCS= .true.
        end if
                                                      
      else if ( VarNum .eq. FCC_DATA ) then ! FCC- Combined force plate cntr pressure
        if ( .not. GetCSAxisNum(CMND.CmndText(cn+1),AxisNum) ) then
          cn= cn + 1
          goto 1070 ! error
        end if
        call ReadFileData( FileNum,VarNum,AxisNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return
        if ( GROPT(GrNum).ShowFpOutline ) GD(GrNum).ShowFpOutline= .true.
        if ( GROPT(GrNum).ShowFtOutLine ) then
          GD(GrNum).FtOutLineGCS= .true.
          do i= 1, 2
            GD(GrNum).FtFileNum(i)= FileNum
            GD(GrNum).ShowFtOutLine(i)= .true.
          end do
        end if
                                    
      else if ( VarNum .eq. FWP_DATA ) then ! FWP- Wrench of raw force plate data
        if ( .not. GetWrenchCompNum(CMND.CmndText(cn+2),CompNum) ) then
          cn= cn + 2
          goto 1080 ! error
        end if
        call ReadFileData( FileNum,VarNum,PltNum,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return
c        if ( GROPT(GrNum).NormWt .or. GROPT(GrNum).NormWtHt ) 
c     &    call NormalizeData( PlotAxis,PlotNum,GrNum,FileNum,error )
c        if ( error ) return
                                                                       
      else if ( VarNum .eq. FWF_DATA ) then ! FWF- Wrench of Ind Foot load data
        if ( .not. GetWrenchCompNum(CMND.CmndText(cn+2),CompNum) ) then
          cn= cn + 2
          goto 1080 ! error
        end if
        call ReadFileData( FileNum,VarNum,side,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return
c        if ( GROPT(GrNum).NormWt .or. GROPT(GrNum).NormWtHt ) 
c     &    call NormalizeData( PlotAxis,PlotNum,GrNum,FileNum,error )
c        if ( error ) return
                                    
      else if ( VarNum .eq. FWC_DATA ) then ! FWC- Wrench of Combined force plate data
        if ( .not. GetWrenchCompNum(CMND.CmndText(cn+1),CompNum) ) then
          cn= cn + 1
          goto 1080 ! error                          
        end if
        call ReadFileData( FileNum,VarNum,CompNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return
c        if ( GROPT(GrNum).NormWt .or. GROPT(GrNum).NormWtHt ) 
c     &    call NormalizeData( PlotAxis,PlotNum,GrNum,FileNum,error )
c        if ( error ) return
                                    
      else if ( (VarNum .eq. FP1_DATA) .or.		! FP1- 1st Integral of force plate data
     &          (VarNum .eq. FP2_DATA)      ) then	! 2nd also
        if ( .not. GetImpCompNum(CMND.CmndText(cn+2),CompNum) ) then
          cn= cn + 2                             
          goto 1090 ! error
        end if
        call ReadFileData( FileNum,VarNum,PltNum,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PlotNum,GrNum,FileNum,error )
        if ( error ) return
      
      else if ( (VarNum .eq. FF1_DATA) .or.		! FF1- 1st Integral of Ind Foot force data
     &          (VarNum .eq. FF2_DATA)     ) then  ! 2nd also
        if ( .not. GetImpCompNum(CMND.CmndText(cn+2),CompNum) ) then
          cn= cn + 2
          goto 1090 ! error
        end if
        call ReadFileData( FileNum,VarNum,side,CompNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PlotNum,GrNum,FileNum,error )
        if ( error ) return

      else if ( (VarNum .eq. FC1_DATA) .or.		! FC1- 1st Integral of combined force plate data
     &          (VarNum .eq. FC2_DATA)      ) then 	! 2nd also
        if ( .not. GetImpCompNum(CMND.CmndText(cn+1),CompNum) ) then
          cn= cn + 1
          goto 1090 ! error
        end if
        call ReadFileData( FileNum,VarNum,CompNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return
        if ( ( GROPT(GrNum).NormWt .or. 
     &         GROPT(GrNum).NormWtHt .or. 
     &         GROPT(GrNum).NormWtLeg ) .and. (.not. DontNormalize)   ) 
     &    call NormalizeData( PlotAxis,PlotNum,GrNum,FileNum,error )
        if ( error ) return
                                                   
      else if ( VarNum .eq. FSI_DATA ) then ! FSI- Foot Strike Index
        if ( .not. GetSide( CMND.CmndText(cn+1),side ) ) goto 1040 ! error
        call ReadFileData( FileNum,VarNum,side,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return               
                                                

      else if ( VarNum .eq. PMA_DATA ) then ! PMA- Pitch Moment Arm
        if ( .not. GetPACompNum(CMND.CmndText(cn+1),CSType,CompNum) ) then
          cn= cn + 1
          goto 1120 ! error
        end if
        call ReadFileData( FileNum,VarNum,CompNum,0,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return

      else if ( VarNum .eq. PWA_DATA ) then ! PWA- Pitch Wrench Arm
        if ( .not. GetPACompNum(CMND.CmndText(cn+1),CSType,CompNum) ) then
          cn= cn + 1
          goto 1120 ! error
        end if
        call ReadFileData( FileNum,VarNum,CompNum,0,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return

      else if ( VarNum .eq. FCV_DATA ) then ! FCV- Cntr Press Vel
        if ( .not. GetCsAxisNum(CMND.CmndText(cn+2),AxisNum) ) then
          cn= cn + 1                
          goto 1070 ! error
        end if
        call ReadFileData( FileNum,VarNum,side,AxisNum,0,0,Start,End,
     &                     PltData(1,PlotAxis,PlotNum,GrNum),
     &                     PltDataOK(1,PlotNum,GrNum),error   )
        if ( error ) return

      end if                        
c           
c     Assign Gait events
c
c    NOTE: frm number calculation below changed (8/92) due to correction by
c          R.Mueller of ETH Zurich - problem occurred with c3d files
c
      EventAssigned= .false.                      
      if ( (FD(FileNum).FP.av_frm_ratio .gt. 1.0e-5) .and.
     &      FD(FileNum).CF.GaitEvent ) then
        do i= Start, End
c          frm= (i-FD(FileNum).FP.frm_offset+1)/FD(FileNum).FP.av_frm_ratio +
c     &      FD(FileNum).MP.cycle_first_frm(1)
          frm= (i-Start)/FD(FileNum).FP.av_frm_ratio + 1
          if ( (frm .lt. 1) .or. (frm .gt. MAX_MTN_FRM) ) then
            PltEvent(i-Start+1,PlotAxis,PlotNum,GrNum)= 0
          else if ( (FD(FileNum).GaitEvent(frm) .ne. 0) .and.
     &              (.not. EventAssigned)                     ) then
            PltEvent(i-Start+1,PlotAxis,PlotNum,GrNum)= FD(FileNum).GaitEvent(frm)
            EventAssigned= .true.
          else if ( (FD(FileNum).GaitEvent(frm) .ne. 0) .and.
     &              EventAssigned                             ) then
            PltEvent(i-Start+1,PlotAxis,PlotNum,GrNum)= 0
          else
            PltEvent(i-Start+1,PlotAxis,PlotNum,GrNum)= 0
            EventAssigned= .false.   
          end if                
        end do                                             
      else
        do i= 1, PD(PlotNum,GrNum).NumPnts
          PltEvent(i,PlotAxis,PlotNum,GrNum)= 0
        end do                  
      end if                    
c
c    Finish up now that the proper quantity has been found and the data assigned
c
      call DataMinMax( PltData(1,PlotAxis,PlotNum,GrNum),
     &                 PltDataOK(1,PlotNum,GrNum),
     &                 PD(PlotNum,GrNum).NumPnts,  
     &                 PD(PlotNum,GrNum).Min(PlotAxis),
     &                 PD(PlotNum,GrNum).Max(PlotAxis)     )
      if ( GROPT(GrNum).ManLgndFlg ) then
        PD(PlotNum,GrNum).Lgnd(PlotAxis)= GROPT(GrNum).ManLgnd(PlotNum)
      else
        PD(PlotNum,GrNum).Lgnd(PlotAxis)= '                    '
        PD(PlotNum,GrNum).Lgnd(PlotAxis)(1:3)= CMND.CmndText(cn)//' '
        j= 5             
        do i= 1, GrNumPrm(VarNum)
          PD(PlotNum,GrNum).Lgnd(PlotAxis)= PD(PlotNum,GrNum).Lgnd(PlotAxis)(1:j)//
     &                                     CMND.CmndText(cn+i)//' '
          j= j + 4
        end do
      end if
      PD(PlotNum,GrNum).File(PlotAxis)= FD(FileNum).GP.motion_file
      PD(PlotNum,GrNum).FileNum(PlotAxis)= FileNum
      PD(PlotNum,GrNum).DataType(PlotAxis)= ELC_DT
      cn= cn + GrNumPrm(VarNum) + 1
      error= .false.              
      return
                       
1000  write(6,1005) VarNames(VarNum),GrNumPrm(VarNum)
1005  format(' Error- Not enough parameters.'/
     &       '       ',a3,' requires',i1', parameters to be graphed.')
      return

1010  write(6,1015) VarNames(VarNum)
1015  format(' Error- Invalid file number in options of ',a3,'.')
      return
       
1020  write(6,1025) VarNames(VarNum)
1025  format(' Error- Invalid coordinate system in options for ',a3/
     &       '        Only [GCS]/LCS are allowed')
      return

1030  write(6,1035) VarNames(VarNum),FD(FileNum).Name
1035  format(' Error- ',a3,' is not available in file ',a40)
      return                        
                    
1040  write(6,1045) CMND.CmndText(cn+1)
1045  format(' Error- ',a3,' is not a valid side name.'/
     &       '        Valid names are: rt lf')
      return

1050  write(6,1055) CMND.CmndIntVal(cn+1)
1055  format(' Error- ',i4,' is not a valid force plate number for this file.'/
     &       '        Plates number 1 - ',i2,' are available.')
      return                                                         
      
1060  write(6,1065) CMND.CmndText(cn),(FrcNames(i),i=1,6)
1065  format(' Error- ',a3,' is not a valid force plate data axis name.'/
     &       '        Valid names are: ',6(a3,1x) )
      return
                                                                     
1070  write(6,1075) CMND.CmndText(cn)
1075  format(' Error- ',a3,' is not a valid coordinate axis name.'/
     &       '        Valid names are: x y z')
      return
      
1080  write(6,1085) CMND.CmndText(cn),(WrenchCompNames(i),i=1,8)
1085  format(' Error- ',a3,' is not a valid force wrench component.'/
     &       '        Valid names are: ',8(a3,1x) )
      return

1090  write(6,1095) CMND.CmndText(cn),(ImpCompNames(i),i=1,4)
1095  format(' Error- ',a3,' is not a valid force impulse component.'/
     &       '        Valid names are: ',4(a3,1x) )
      return

1100  write(6,1105) CMND.OptText(i,cn),CMND.CmndText(cn),NumFileOpen
1105  format(' Error- ',a3,' is an invalid option for ',a3/
     &       '        Valid options are: File #''s 1 to ',i1/
     &       '                           GCS LCS')
      return

1110  write(6,1115) VarNames(VarNum)
1115  format(' Error- Invalid coordinate system in options for ',a3/
     &       '        Only [GCS]/PLV/TRK are allowed')
      return

1120  j= 3
      if ( CSType .eq. GCS_CST ) j= 4
      write(6,1125) CMND.CmndText(cn),(PitArmCompNames(i),i=1,j)
1125  format(' Error- ',a3,' is not a valid moment/wrench arm component.'/
     &       '        Valid names are: ',4(a3,1x) )
      return

2070  write(6,2075) GrNum,FileNum,FD(FileNum).Name                
2075  format(' Error- Cycle clip set for force data in graph # ',i2/
     &       '        However, gait event data not present in file # ',i2/
     &       '        File name: ',a40)
      return
      end
c                                                               
c   Copyright (c) 1990 by Dwight Meglan                   
c           
      subroutine AssignRecData( cn,CMND,VarNum,DefFileNum,   
     &                          PlotAxis,PltNum,GrNum,error )
      implicit none
               
      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'
      include 'tel_name.inc'
                          
      record /CmndLine/    CMND
      integer*4 cn,VarNum,DefFileNum,PlotAxis,PltNum,GrNum
      logical*4 error

      integer*4 FileNum,CSType,Start,End,side,AxisNum,i,j
      logical*4 GetFileNum,GetCSType,RecVarAvailable,GetSide,GetFrcAxisNum,
     &          GetCSAxisNum,resultOK
c
c     Find the file number and check whether force variable is available
c
      error= .true.
      if ( cn+GrNumPrm(VarNum) .gt. CMND.NumCmnd ) goto 1000 ! error, not enough cmnds
      CSType= GCS_CST
      do i= 1, CMND.NumOpt(cn)
        if ( CMND.OptNumOK(i,cn) ) then
          resultOK= GetFileNum( CMND.NumOpt(cn),CMND.OptNumOK(i,cn),
     &                          CMND.OptIntVal(i,cn),DefFileNum,FileNum )
          if ( .not. resultOK ) goto 1010 ! error in file #
        else if ( (VarNum .eq. RFT_DATA) .or. 
     &            (VarNum .eq. RCF_DATA)      ) then ! check for CSType
          if ( .not. GetCSType(CMND.NumOpt(cn),CMND.OptText(i,cn),CSType) )
     &       CSType= GCS_CST ! GCS       
          if ( CSType .gt. LCS_CST ) goto 1020 ! error, bad CS type
        else
          goto 1070 ! error in option...
        end if
      end do
      if ( (FileNum .le. 0) .or. (FileNum .gt. NumFileOpen) ) FileNum= DefFileNum
c                           
c     Check availability of data
c
      if ( .not. RecVarAvailable(VarNum,CSType,FileNum) ) goto 1030 ! error
c                    
c     If Graph option is set to CycleClip, then set data limits accordingly
c
      if ( GROPT(GrNum).CycleClip .and. 
     &     .not. FD(FileNum).CF.GaitEvent ) goto 2070 ! error
      if ( GROPT(GrNum).CycleClip ) then
        Start= FD(FileNum).MP.cycle_first_frm(1)
        End=   FD(FileNum).MP.cycle_last_frm(1)
        PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.cycle_length(1)
      else
        Start= 1 
        if ( FD(FileNum).ExcessNumMtnFrm ) then
          End= FD(FileNum).OrigNumMtnFrm
          PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumMtnFrm
        else
          End=   FD(FileNum).MP.num_frm
          PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.num_frm
        end if
      end if
      if ( End-Start+1 .gt. MAX_PLOT_SIZE ) then ! this check is just a
        End= Start + MAX_PLOT_SIZE - 1           ! precaution...
        write(6,100) PltNum,GrNum,MAX_PLOT_SIZE
100     format(' Warning- Data for plot# ',i2,' graph# ',i1,' has been clipped',
     &         ' at ',i5,' points')
      end if
c                                                            
c     Based upon which reconstructed ground reaction load variable is to 
c     be graphed, assign data                            
c                                     
      if ( VarNum .eq. RFT_DATA ) then ! RFT - foot GRL
        if ( .not. GetSide( CMND.CmndText(cn+1),side ) ) goto 1040 ! error
        if ( .not. GetFrcAxisNum(CMND.CmndText(cn+2),AxisNum) ) then
          cn= cn + 2
          goto 1050 ! error
        end if
        call ReadFileData( FileNum,VarNum,side,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        if ( GROPT(GrNum).NormWt .or. 
     &       GROPT(GrNum).NormWtHt .or. 
     &       GROPT(GrNum).NormWtLeg     ) 
     &    call NormalizeData( PlotAxis,PltNum,GrNum,FileNum,error )
        if ( error ) return
        
      else if ( VarNum .eq. RCB_DATA ) then ! RCB - combined GRL
        if ( .not. GetFrcAxisNum(CMND.CmndText(cn+1),AxisNum) ) then
          cn= cn + 1
          goto 1050 ! error
        end if
        call ReadFileData( FileNum,VarNum,AxisNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
      
      else if ( VarNum .eq. RCF_DATA ) then ! RCF - foot center of pressure
        if ( .not. GetSide( CMND.CmndText(cn+1),side ) ) goto 1040 ! error
        if ( .not. GetCSAxisNum(CMND.CmndText(cn+2),AxisNum) ) then
          cn= cn + 2
          goto 1060 ! error
        end if
        if ( AxisNum .gt. 3 ) goto 1060
        call ReadFileData( FileNum,VarNum,side,AxisNum,0,CSType,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
        
      else if ( VarNum .eq. RCC_DATA ) then ! RCC - combined center of pressure
        if ( .not. GetCSAxisNum(CMND.CmndText(cn+1),AxisNum) ) then
          cn= cn + 1
          goto 1060 ! error
        end if
        if ( AxisNum .gt. 3 ) goto 1060
        call ReadFileData( FileNum,VarNum,AxisNum,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return

      else if ( VarNum .eq. RSI_DATA ) then ! RSI - Strike Index
        if ( .not. GetSide( CMND.CmndText(cn+1),side ) ) goto 1040 ! error
        call ReadFileData( FileNum,VarNum,side,0,0,0,Start,End,
     &                     PltData(1,PlotAxis,PltNum,GrNum),
     &                     PltDataOK(1,PltNum,GrNum),error   )
        if ( error ) return
                                   
      end if
c           
c     Assign Gait Events
c
      if ( FD(FileNum).CF.GaitEvent ) then
        do i= Start, End
          PltEvent(i-Start+1,PlotAxis,PltNum,GrNum)= FD(FileNum).GaitEvent(i)
        end do
      else
        do i= 1, PD(PltNum,GrNum).NumPnts
          PltEvent(i,PlotAxis,PltNum,GrNum)= 0
        end do
      end if
c
c    Finish up now that the proper quantity has been found and the data assigned
c
      call DataMinMax( PltData(1,PlotAxis,PltNum,GrNum),
     &                 PltDataOK(1,PltNum,GrNum),
     &                 PD(PltNum,GrNum).NumPnts,  
     &                 PD(PltNum,GrNum).Min(PlotAxis),
     &                 PD(PltNum,GrNum).Max(PlotAxis)     )
      if ( GROPT(GrNum).ManLgndFlg ) then
        PD(PltNum,GrNum).Lgnd(PlotAxis)= GROPT(GrNum).ManLgnd(PltNum)
      else
        PD(PltNum,GrNum).Lgnd(PlotAxis)= '                    '
        PD(PltNum,GrNum).Lgnd(PlotAxis)(1:3)= CMND.CmndText(cn)//' '
        j= 5             
        do i= 1, GrNumPrm(VarNum)
          PD(PltNum,GrNum).Lgnd(PlotAxis)= PD(PltNum,GrNum).Lgnd(PlotAxis)(1:j)//
     &                                     CMND.CmndText(cn+i)//' '
          j= j + 4
        end do
      end if
      PD(PltNum,GrNum).File(PlotAxis)= FD(FileNum).GP.motion_file
      PD(PltNum,GrNum).FileNum(PlotAxis)= FileNum        
      PD(PltNum,GrNum).DataType(PlotAxis)= MTN_DT
      cn= cn + GrNumPrm(VarNum) + 1
      error= .false.                     
      return
      
1000  write(6,1005) VarNames(VarNum),GrNumPrm(VarNum)
1005  format(' Error- Not enough parameters.'/
     &       '       ',a3,' requires',i1', parameters to be graphed.')
      return     

1010  write(6,1015) VarNames(VarNum)
1015  format(' Error- Invalid file number in options of ',a3,'.')
      return
                 
1020  write(6,1025) VarNames(VarNum)
1025  format(' Error- Invalid coordinate system in options for ',a3/
     &       '        Only [GCS]/LCS are allowed')
      return     

1030  write(6,1035) VarNames(VarNum),FD(FileNum).Name
1035  format(' Error- ',a3,' is not available in file ',a40)
      return
                 
1040  write(6,1045) CMND.CmndText(cn+1)
1045  format(' Error- ',a3,' is not a valid side.'/
     &       '        Valid sides are: rt lf')
      return
      
1050  write(6,1055) CMND.CmndText(cn),(FrcNames(i),i=1,6)
1055  format(' Error- ',a3,' is not a valid load data axis name.'/
     &       '        Valid names are: ',6(a3,1x) )
      return
                                                                     
1060  write(6,1065) CMND.CmndText(cn)
1065  format(' Error- ',a3,' is not a valid coordinate axis name.'/
     &       '        Valid names are: x y z')
      return

1070  write(6,1075) CMND.OptText(i,cn),CMND.CmndText(cn),NumFileOpen
1075  format(' Error- ',a3,' is an invalid option for ',a3/
     &       '        Valid options are: File #''s 1 to ',i1/
     &       '                           GCS LCS')
      return

2070  write(6,2075) GrNum,FileNum,FD(FileNum).Name                
2075  format(' Error- Cycle clip set for reconstruction data in graph # ',i2/
     &       '        However, gait event data not present in file # ',i2/
     &       '        File name: ',a40)
      return
      end                                         
c
c   Copyright (c) 1990 by Dwight Meglan
c                  
      subroutine AssignEmgData( cn,CMND,VarNum,DefFileNum,
     &                          PlotAxis,PltNum,GrNum,error )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'
      include 'tel_name.inc'
      
      record /CmndLine/    CMND
      integer*4 cn,VarNum,DefFileNum,PlotAxis,PltNum,GrNum
      logical*4 error,EventAssigned

      real*4    ratio
      integer*4 Start,End,FileNum,i,j,Chnl,frm
      logical*4 GetFileNum,AssignName

      error= .true.
c                
c     Check for YTI option described below- if found remove it from the options
c     of CMND number cn
c
      AssignName= .false.
      i= 1
      do while ( i  .le. CMND.NumOpt(cn) )
        if ( CMND.OptText(i,cn) .eq. 'YTI' ) then
          AssignName= .true.
          call RemoveCMNDOpt( CMND,cn,i )
          i= i - 1
        end if
        i= i + 1
      end do                                 
c
      if ( .not. GetFileNum( CMND.NumOpt(cn),CMND.OptNumOK(1,cn),
     &                       CMND.OptIntVal(1,cn),DefFileNum,  
     &                       FileNum )          ) goto 1000 ! error
      if ( GROPT(GrNum).CycleClip .and. 
     &     .not. FD(FileNum).CF.GaitEvent ) goto 2070 ! error
      if ( GROPT(GrNum).CycleClip ) then
        if ( FD(FileNum).FF.DataClipped ) then
          Start= 1
          if ( FD(FileNum).ExcessNumEmgFrm ) then
            End= FD(FileNum).OrigNumEmgFrm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumEmgFrm
          else
            End=   FD(FileNum).Ep.NumSamples
            PD(PltNum,GrNum).NumPnts= FD(FileNum).EP.NumSamples
          end if
        else if ( FD(FileNum).FF.IndFt ) then
          Start= FD(FileNum).FP.first_frm
          End=   FD(FileNum).FP.last_frm
          PD(PltNum,GrNum).NumPnts= End - Start + 1
        else
          Start= 1
          if ( FD(FileNum).ExcessNumEmgFrm ) then
            End= FD(FileNum).OrigNumEmgFrm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumEmgFrm
          else
            End=   FD(FileNum).Ep.NumSamples
            PD(PltNum,GrNum).NumPnts= FD(FileNum).EP.NumSamples
          end if
          write(6,500)
500       format(/' Warning- EMG channels will probably not align correctly'/)
        end if                               
      else
        Start= 1                             
        if ( FD(FileNum).ExcessNumEmgFrm ) then
          End= FD(FileNum).OrigNumEmgFrm
          PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumEmgFrm
        else
          End=   FD(FileNum).Ep.NumSamples
          PD(PltNum,GrNum).NumPnts= FD(FileNum).EP.NumSamples
        end if
      end if                                          
      if ( End-Start+1 .gt. MAX_PLOT_SIZE ) then ! this check is just a      
        End= Start + MAX_PLOT_SIZE - 1           ! precaution...
        write(6,100) PltNum,GrNum,MAX_PLOT_SIZE
100     format(' Warning- Data for plot# ',i2,' graph# ',i1,' has been clipped',
     &         ' at ',i5,' points')
      end if
c
c     Check emg channel number
c
      Chnl= CMND.CmndIntVal(cn+1)
      if ( (Chnl .lt. 1) .or.
     &     (Chnl .gt. FD(FileNum).EP.NumChnl) ) goto 1010
c                                                                            
c     Check for option on EMG command /yti which will make the emg channel name
c     which is usually the muscle name be assigned to the plot y axis title
c     This is a hack to make it easier to display the muscle names in the
c     SCHart display mode.  This will cause havoc if used in any other case!!!
c
      if ( AssignName ) then
        do j= 1, 40
          GD(GrNum).YTitle(j:j)= ' '
        end do
        GD(GrNum).YTitle(1:20)= FD(FileNum).EP.Name(Chnl)
      end if
c
c     Assign data
c
c     NOTE: Ratio and frm calculations changed (8/92) due to corrections of
c           R.Mueller of ETH Zurich
c
c
      call ReadFileData( FileNum,VarNum,Chnl,0,0,0,Start,End,
     &                   PltData(1,PlotAxis,PltNum,GrNum),
     &                   PltDataOK(1,PltNum,GrNum),error   )
      if ( error ) return  
      if ( FD(FileNum).CF.GaitEvent ) then
        if ( FD(FileNum).EP.SampleRate .lt. 1.0e-5 ) goto 1020
c        ratio= FD(FileNum).rMtnFrmRate/float(FD(FileNum).EP.SampleRate)
c        do i= Start, End
c          frm= (i-FD(FileNum).FP.first_frm+1)/ratio
        ratio= float(FD(FileNum).EP.SampleRate)/FD(FileNum).rMtnFrmRate
        do i= Start, End
          frm= (i-Start)/ratio + 1
          if ( (frm .lt. 1) .or. (frm .gt. MAX_MTN_FRM) ) then
            PltEvent(i-Start+1,PlotAxis,PltNum,GrNum)= 0
          else if ( (FD(FileNum).GaitEvent(frm) .ne. 0) .and.
     &              (.not. EventAssigned)                     ) then
            PltEvent(i-Start+1,PlotAxis,PltNum,GrNum)= FD(FileNum).GaitEvent(frm)
            EventAssigned= .true.
          else if ( (FD(FileNum).GaitEvent(frm) .ne. 0) .and.
     &              EventAssigned                             ) then
            PltEvent(i-Start+1,PlotAxis,PltNum,GrNum)= 0
          else
            PltEvent(i-Start+1,PlotAxis,PltNum,GrNum)= 0
            EventAssigned= .false.   
          end if                
        end do
      else
        do i= 1, PD(PltNum,GrNum).NumPnts
          PltEvent(i,PlotAxis,PltNum,GrNum)= 0
        end do                  
      end if
c                      
c    Finish up now that the proper quantity has been found and the data assigned
c
      call DataMinMax( PltData(1,PlotAxis,PltNum,GrNum),
     &                 PltDataOK(1,PltNum,GrNum),
     &                 PD(PltNum,GrNum).NumPnts,  
     &                 PD(PltNum,GrNum).Min(PlotAxis),
     &                 PD(PltNum,GrNum).Max(PlotAxis)     )
      if ( GROPT(GrNum).ManLgndFlg ) then
        PD(PltNum,GrNum).Lgnd(PlotAxis)= GROPT(GrNum).ManLgnd(PltNum)
      else
        PD(PltNum,GrNum).Lgnd(PlotAxis)= '                    '
        PD(PltNum,GrNum).Lgnd(PlotAxis)(1:3)= CMND.CmndText(cn)//' '
        j= 5             
        do i= 1, GrNumPrm(VarNum)
          PD(PltNum,GrNum).Lgnd(PlotAxis)= PD(PltNum,GrNum).Lgnd(PlotAxis)(1:j)//
     &                                     CMND.CmndText(cn+i)//' '
          j= j + 4
        end do
      end if
      PD(PltNum,GrNum).File(PlotAxis)= FD(FileNum).GP.force_file
      PD(PltNum,GrNum).FileNum(PlotAxis)= FileNum
      PD(PltNum,GrNum).DataType(PlotAxis)= EMG_DT       
      cn= cn + 2
      error= .false.              
      return
      
1000  write(6,1005) CMND.CmndText(cn)
1005  format(' Error- Invalid file number in options of ',a3,'.')
      return

1010  write(6,1015) CMND.CmndText(cn+1),FD(FileNum).EP.NumChnl
1015  format(' Error- ',a3,' is an invalid emg channel number'/
     &       '        Valid channels are 1 to ',i2)
      return                                                  

1020  write(6,1025) FD(FileNum).Name,FD(FileNum).EP.SampleRate
1025  format(' Error- The sample rate for the emg data for file ',a40/
     &       '        is ',f12.4,' which is not physically possible')
      return

1030  write(6,1035) CMND.OptText(i,cn)
1035  format(' Error- ',a3,' is not a valid option for EMG'/
     &       '        The only valid option is /YTItle')
      return                                            

2070  write(6,2075) GrNum,FileNum,FD(FileNum).Name                
2075  format(' Error- Cycle clip set for EMG data in graph # ',i2/
     &       '        However, gait event data not present in file # ',i2/
     &       '        File name: ',a40)
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan                     
c                  
      subroutine AssignTimeData( cn,CMND,VarNum,DefFileNum,
     &                           PlotAxis,PltNum,GrNum,error )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'
      include 'tel_name.inc'

      record /CmndLine/    CMND
      integer*4 cn,VarNum,DefFileNum,PlotAxis,PltNum,GrNum
      logical*4 error

      real*4    FrmRate
      integer*4 Start,End,FileNum,i
      logical*4 GetFileNum

*$ifdef DEBUG
      write(2,790) cn,CMND.Text(1)(CMND.CmndStart(cn):CMND.CmndEnd(cn))
 790  format(' AssignTimeData'/
     &       ' Command #: ',i2/
     &       ' Cmnd Text: ',a20)
*$endif

      error= .true.          
      if ( .not. GetFileNum( CMND.NumOpt(cn),CMND.OptNumOK(1,cn),
     &                       CMND.OptIntVal(1,cn),DefFileNum,  
     &                       FileNum )          ) goto 1000 ! error
      if ( (PD(PltNum,GrNum).DataType(y) .eq. FRC_DT) .or.
     &     (PD(PltNum,GrNum).DataType(y) .eq. ELC_DT)      ) then
        FrmRate= float(FD(FileNum).FP.frm_rate)
      else if ( PD(PltNum,GrNum).DataType(y) .eq. EMG_DT ) then
        FrmRate= float(FD(FileNum).EP.SampleRate)
      else
        FrmRate= FD(FileNum).rMtnFrmRate
      end if
c                                            
c     Set up cycle frame # start and end
c                        
      if ( GROPT(GrNum).CycleClip .and. 
     &     .not. FD(FileNum).CF.GaitEvent ) goto 2070 ! error
      if ( GROPT(GrNum).CycleClip ) then
        if ( PD(PltNum,GrNum).DataType(y) .eq. MTN_DT ) then
          Start= FD(FileNum).MP.cycle_first_frm(1)
          End=   FD(FileNum).MP.cycle_last_frm(1)
          PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.cycle_length(1)
          if ( Start .eq. End ) then
            Start= 1
            if ( FD(FileNum).ExcessNumMtnFrm ) then
              End= FD(FileNum).OrigNumMtnFrm
              PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumMtnFrm
            else
              End=   FD(FileNum).MP.num_frm
              PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.num_frm
            end if
          end if
        else if ( PD(PltNum,GrNum).DataType(y) .eq. EMG_DT ) then
          Start= 1
          if ( FD(FileNum).ExcessNumEmgFrm ) then
            End= FD(FileNum).OrigNumEmgFrm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumEmgFrm
          else
            if ( FD(FileNum).FF.DataClipped ) then
              End=   FD(FileNum).EP.NumSamples
              PD(PltNum,GrNum).NumPnts= FD(FileNum).EP.NumSamples
            else if ( FD(FileNum).FF.indFt ) then
              Start= FD(FileNum).FP.first_frm
              End=   FD(FileNum).FP.last_frm
              PD(PltNum,GrNum).NumPnts= End - Start + 1
            else
              End=   FD(FileNum).EP.NumSamples
              PD(PltNum,GrNum).NumPnts= FD(FileNum).EP.NumSamples
              write(6,500)
500           format(/'Warning- EMG channel time data might be wrong'/)
            end if
          end if 
        else
          Start= FD(FileNum).FP.first_frm
          End=   FD(FileNum).FP.last_frm
          PD(PltNum,GrNum).NumPnts= End - Start + 1
        end if
      else
        Start= 1        
        if ( (PD(PltNum,GrNum).DataType(y) .eq. ELC_DT) .or.
     &       (PD(PltNum,GrNum).DataType(y) .eq. FRC_DT)      ) then
          if ( FD(FileNum).ExcessNumFrcFrm ) then
            End= FD(FileNum).OrigNumFrcFrm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumFrcFrm
          else
            End=   FD(FileNum).FP.num_frm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).FP.num_frm
          end if
        else if ( PD(PltNum,GrNum).DataType(y) .eq. EMG_DT ) then
          if ( FD(FileNum).ExcessNumEmgFrm ) then
            End= FD(FileNum).OrigNumEmgFrm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumEmgFrm
          else
            End=   FD(FileNum).Ep.NumSamples
            PD(PltNum,GrNum).NumPnts= FD(FileNum).EP.NumSamples
          end if
        else                                      
          if ( FD(FileNum).ExcessNumMtnFrm ) then
            End= FD(FileNum).OrigNumMtnFrm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).OrigNumMtnFrm
          else
            End=   FD(FileNum).MP.num_frm
            PD(PltNum,GrNum).NumPnts= FD(FileNum).MP.num_frm
          end if
        end if
      end if                                              
      if ( End-Start+1 .gt. MAX_PLOT_SIZE ) then ! this check is just a
        End= Start + MAX_PLOT_SIZE - 1           ! precaution...
        write(6,100) PltNum,GrNum,MAX_PLOT_SIZE
100     format(' Warning- Data for plot# ',i2,' graph# ',i1,' has been clipped',
     &         ' at ',i5,' points')
      end if     
c           
c     Assign the proper time quantity to PD    
c                                     
      if ( VarNum .eq. TIM_DATA ) then ! TIMe
        if ( FrmRate .lt. 1.0e-5 ) goto 1010 ! error
        do i= Start, End                              
          PltData(i-Start+1,PlotAxis,PltNum,GrNum)= float(i-1)/FrmRate
c          PltDataOK(i-Start+1,PltNum,GrNum)= .true.
        end do                                    
        PD(PltNum,GrNum).Lgnd(PlotAxis)= 'Time (sec)'

      else if ( VarNum .eq. FRA_DATA ) then ! FRAme number
        do i= Start, End                              
          PltData(i-Start+1,PlotAxis,PltNum,GrNum)= i
c          PltDataOK(i-Start+1,PltNum,GrNum)= .true.
        end do            
        PD(PltNum,GrNum).Lgnd(PlotAxis)= 'Frame Number'
                                            
      else if ( VarNum .eq. PCT_DATA ) then ! PERcent of frame or cycle
        if ( PD(PltNum,GrNum).NumPnts .lt. 1 ) goto 1020 ! error
        do i= Start, End                              
          PltData(i-Start+1,PlotAxis,PltNum,GrNum)= 100.0*(i-Start)/
     &                                      float(PD(PltNum,GrNum).NumPnts-1)
c          PltDataOK(i-Start+1,PltNum,GrNum)= .true.
        end do
        if ( GROPT(GrNum).CycleClip ) then
          PD(PltNum,GrNum).Lgnd(PlotAxis)= 'Percent Cycle (%)'
        else                        
          PD(PltNum,GrNum).lgnd(PlotAxis)= 'Percent Data Set (%)'
        end if
      end if
c
c    Finish up now that the proper quantity has been found and the data assigned
c
      do i= 1, PD(PltNum,GrNum).NumPnts
        PltEvent(i,PlotAxis,PltNum,GrNum)= PltEvent(i,y,PltNum,GrNum)
      end do
      PD(PltNum,GrNum).Min(x)= PltData(1,PlotAxis,PltNum,GrNum)
      PD(PltNum,GrNum).Max(x)= 
     &  PltData(PD(PltNum,GrNum).NumPnts,PlotAxis,PltNum,GrNum)
      PD(PltNum,GrNum).File(x)= FD(FileNum).GP.motion_file
      PD(PltNum,GrNum).FileNum(x)= FileNum
      PD(PltNum,GrNum).DataType(x)= TIM_DT
      cn= cn + 1
      error= .false.              
      return

1000  write(6,1005) CMND.CmndText(cn)
1005  format(' Error- Invalid file number in options of ',a3,'.')
      return
      
1010  write(6,1015) FrmRate
1015  format(' Error- Invalid frame rate.'/
     &       '        Present frame rate is ',f8.3,' frm/sec'/
     &       '        Valid frame rates are greater than 0.')
      return

1020  write(6,1025) PD(PltNum,GrNum).NumPnts
1025  format(' Error- Invalid number of points in plot'/
     &       '        Present number of points is set at ',i3/
     &       '        Valid number of points must be greater than 0.')
      return

2070  write(6,2075) GrNum,FileNum,FD(FileNum).Name                
2075  format(' Error- Cycle clip set for time data in graph # ',i2/
     &       '        However, gait event data not present in file # ',i2/
     &       '        File name: ',a40)
      return
      end                    
c
c   Copyright (c) 1990 by Dwight Meglan                     
c                  
      subroutine AssignMslData( cn,CMND,VarNum,DefFileNum,
     &                          PlotAxis,PltNum,GrNum,error )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'

      record /CmndLine/    CMND
      integer*4 cn,VarNum,DefFileNum,PlotAxis,PltNum,GrNum
      logical*4 error

      error= .true.
      write(6,100)
100   format(' Error- Muscle information is not supported yet')
      return
      end
c                                  
c                                            
c   Copyright (c) 1990 by Dwight Meglan                                           
c                                                                      
      logical*4 function MrkCmnd( Text,CmndNum )
      implicit none                   

      include 'tel_name.inc'
                      
      integer*4 CmndNum,i
      character Text*3
c
c     Change the min/max numbers (1,3) if tel_cons.inc is changed    
c
      i= 1					
      MrkCmnd= .false.   
      do while ( (i .le. 3) .and. (.not. MrkCmnd) )
        if ( Text .eq. VarNames(i) ) then
          MrkCmnd= .true.
          CmndNum= i
        end if
        i= i + 1
      end do  
      return
      end       
c                        
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function SegCmnd( Text,CmndNum )
      implicit none
            
      include 'tel_name.inc'
                     
      integer*4 CmndNum,i
      character Text*3
c
c     Change the min/max numbers (4,22) if tel_cons.inc is changed    
c
      i= 4
      SegCmnd= .false.
      do while ( (i .le. 22) .and. (.not. SegCmnd) )
        if ( Text .eq. VarNames(i) ) then
          SegCmnd= .true.
          CmndNum= i
        end if
        i= i + 1
      end do
      return
      end             
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function JntCmnd( Text,CmndNum )
      implicit none

      include 'tel_name.inc'
          
      integer*4 CmndNum,i
      character Text*3
c
c     Change the min/max numbers (23,36) if tel_cons.inc is changed    
c
      i= 23
      JntCmnd= .false.
      do while ( (i .le. 36) .and. (.not. JntCmnd) )
        if ( Text .eq. VarNames(i) ) then
          JntCmnd= .true.  
          CmndNum= i
        end if
        i= i + 1
      end do  
      return    
      end       
c
c   Copyright (c) 1990 by Dwight Meglan
c             
      logical*4 function FrcCmnd( Text,CmndNum )
      implicit none

      include 'tel_name.inc'
                           
      integer*4 CmndNum,i
      character Text*3
c
c     Change the min/max numbers (37,55) if tel_cons.inc is changed    
c
      i= 37
      FrcCmnd= .false.
      do while ( (i .le. 55) .and. (.not. FrcCmnd) )
        if ( Text .eq. VarNames(i) ) then
          FrcCmnd= .true.
          CmndNum= i       
        end if             
        i= i + 1
      end do
      return
      end                  
c                   
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function RecCmnd( Text,CmndNum )
      implicit none

      include 'tel_name.inc'
          
      integer*4 CmndNum,i
      character Text*3
c
c     Change the min/max numbers (56,60) if tel_cons.inc is changed    
c
      i= 56
      RecCmnd= .false.
      do while ( (i .le. 60) .and. (.not. RecCmnd) )
        if ( Text .eq. VarNames(i) ) then
          RecCmnd= .true.  
          CmndNum= i       
        end if
        i= i + 1
      end do    
      return
      end       
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function MslCmnd( Text,CmndNum )
      implicit none

      include 'tel_name.inc'
          
      integer*4 CmndNum,i
      character Text*3
c
c     Change the min/max numbers (62,67) if tel_cons.inc is changed    
c
      i= 62
      MslCmnd= .false.
      do while ( (i .le. 67) .and. (.not. MslCmnd) )
        if ( Text .eq. VarNames(i) ) then
          MslCmnd= .true.  
          CmndNum= i       
        end if  
        i= i + 1
      end do    
      return
      end                  
c                            
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function TimeCmnd( Text,CmndNum )
      implicit none

      include 'tel_name.inc'
                           
      integer*4 CmndNum,i                  
      character Text*3 
c
c     Change the min/max numbers (68,70) if tel_cons.inc is changed    
c
      i= 68
      TimeCmnd= .false.
      do while ( (i .le. 70) .and. (.not. TimeCmnd) )
        if ( Text .eq. VarNames(i) ) then
          TimeCmnd= .true.
          CmndNum= i       
        end if
        i= i + 1
      end do
      return          
      end                
c                          
c   Copyright (c) 1990 by Dwight Meglan
c               
      logical*4 function GetCSType(NumOpt,Text,CSType)
      implicit none
c
c     Types of coordinate systems. These are defined in tel_cons.inc
c      Global (GCS)        - 1
c      Local Segment (LCS) - 2
c      Proximal Segment    - 3
c      Distal Segment      - 4
c      Joint (JCS)         - 5
c      Euler (EUL)         - 6
c      Pelvis (PLV)        - 7
c      Trunk  (TRK)        - 8
c
      include 'tel_name.inc'
                           
      integer*4 CSType,i,j,NumOpt
      character Text(5)*3

      GetCSType= .false.
      j= 1                    
      do while ( (j .le. NumOpt) .and. (.not. GetCSType) )
        i= 1
        do while ( (i .le. 8) .and. (.not. GetCSType) )
          if ( Text(j) .eq. CSTypeNames(i) ) then
            CSType= i
            GetCSType= .true.
          end if
          i= i + 1
        end do
        j= j + 1
      end do
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function GetCsAxisNum( Text,AxisNum )
      implicit none

      include 'tel_name.inc'

      integer*4 AxisNum,i
      character Text*3
                
      GetCsAxisNum= .false.
      i= 1
      do while ( (i .le. 3) .and. (.not. GetCsAxisNum) )
        if ( Text .eq. CSAxes(i) ) then
          GetCsAxisNum= .true.
          AxisNum= i
        end if
        i= i + 1
      end do    
      return
      end       
c             
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function GetMtnAxisNum( Text,AxisNum )
      implicit none

      include 'tel_name.inc'
          
      integer*4 AxisNum,i
      character Text*3

      GetMtnAxisNum= .false.
      i= 1
      do while ( (i .le. 6) .and. (.not. GetMtnAxisNum) )
        if ( Text .eq. CSAxes(i) ) then
          GetMtnAxisNum= .true.
          AxisNum= i
        end if
        i= i + 1
      end do
      return
      end       
c                  
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function GetAngAxisNum( Text,AxisNum )
      implicit none

      include 'tel_name.inc'                         

      integer*4 AxisNum,i
      character Text*3

      GetAngAxisNum= .false.
      i= 1
      do while ( (i .le. 3) .and. (.not. GetAngAxisNum) )
        if ( Text .eq. AngAxes(i) ) then
          GetAngAxisNum= .true.
          AxisNum= i
        end if
        i= i + 1
      end do
      return
      end               
c
c   Copyright (c) 1990 by Dwight Meglan
c                      
      logical*4 function GetFrcAxisNum( Text,AxisNum )
      implicit none

      include 'tel_name.inc'
          
      integer*4 AxisNum,i
      character Text*3

      GetFrcAxisNum= .false.
      i= 1
      do while ( (i .le. 6) .and. (.not. GetFrcAxisNum) )
        if ( Text .eq. FrcNames(i) ) then
          GetFrcAxisNum= .true.
          AxisNum= i
        end if
        i= i + 1
      end do
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c                      
      logical*4 function GetJCSFrcAxisNum( Text,AxisNum )
      implicit none

      include 'tel_name.inc'
          
      integer*4 AxisNum,i
      character Text*3

      GetJCSFrcAxisNum= .false.
      i= 1
      do while ( (i .le. 8) .and. (.not. GetJCSFrcAxisNum) )
        if ( Text .eq. JCSFrcNames(i) ) then
          GetJCSFrcAxisNum= .true.
          AxisNum= i
        end if               
        i= i + 1
      end do
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function GetKECompNum( Text,CompNum )
      implicit none

      integer*4 CompNum
      character Text*3

      GetKECompNum= .false.
      if ( Text .eq. 'ROT' ) then ! rotational component
        GetKECompNum= .true.
        CompNum= 1
      else if ( Text .eq. 'TRA' ) then ! translational component
        GetKECompNum= .true.
        CompNum= 2
      else if ( Text .eq. 'TOT' ) then ! total energy
        GetKECompNum= .true.
        CompNum= 3
      end if
      return             
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c                        
      logical*4 function GetScrewCompNum( Text,CompNum )
      implicit none

      include 'tel_name.inc'

      integer*4 CompNum,i
      character Text*3

      i= 1        
      GetScrewCompNum= .false.
      do while ( (i .le. 8) .and. (.not. GetScrewCompNum) )
        if ( Text .eq. ScrewCompNames(i) ) then
          CompNum= i
          GetScrewCompNum= .true.
        end if
        i= i + 1
      end do
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function GetWrenchCompNum( Text,CompNum )
      implicit none

      include 'tel_name.inc'

      integer*4 CompNum,i
      character Text*3

      i= 1        
      GetWrenchCompNum= .false.
      do while ( (i .le. 8) .and. (.not. GetWrenchCompNum) )
        if ( Text .eq. WrenchCompNames(i) ) then
          CompNum= i
          GetWrenchCompNum= .true.
        end if
        i= i + 1
      end do
      return           
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function GetPowerCompNum( Text,CompNum )
      implicit none

      include 'tel_name.inc'

      integer*4 CompNum,i
      character Text*3

      i= 1        
      GetPowerCompNum= .false.
      do while ( (i .le. 4) .and. (.not. GetPowerCompNum) )
        if ( Text .eq. PowerCompNames(i) ) then
          CompNum= i
          GetPowerCompNum= .true.
        end if
        i= i + 1
      end do
      return           
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function GetTransCompNum( Text,CSType,CompNum )
      implicit none

      include 'tel_cons.inc'
      include 'tel_name.inc'   

      integer*4 CompNum,i,CSType
      character Text*3

      i= 1        
      GetTransCompNum= .false.
      do while ( (i .le. 4) .and. (.not. GetTransCompNum) )
        if ( CSType .eq. JCS_CST ) then
          if ( Text .eq. JCSTransCompNames(i) ) then
            CompNum= i         
            GetTransCompNum= .true.
          end if
        else
          if ( Text .eq. TransCompNames(i) ) then
            CompNum= i         
            GetTransCompNum= .true.
          end if
        end if
        i= i + 1
      end do
      return           
      end             
c                                                     
c   Copyright (c) 1990 by Dwight Meglan
c        
      logical*4 function GetMomCompNum( Text,CompNum )
      implicit none

      include 'tel_name.inc'

      integer*4 CompNum,i
      character Text*3

      GetMomCompNum= .false.
      i= 1
      do while ( (i .le. 8) .and. (.not. GetMomCompNum) )
        if ( Text .eq. MomCompNames(i) ) then
          CompNum= i
          GetMomCompNum= .true.
        end if
        i= i + 1
      end do
      return
      end
c               
c   Copyright (c) 1990 by Dwight Meglan
c        
      logical*4 function GetImpCompNum( Text,CompNum )
      implicit none

      include 'tel_name.inc'
                
      integer*4 CompNum,i
      character Text*3

      GetImpCompNum= .false.
      i= 1
      do while ( (i .le. 4) .and. (.not. GetImpCompNum) )
        if ( Text .eq. ImpCompNames(i) ) then
          CompNum= i                                  
          GetImpCompNum= .true.
        end if
        i= i + 1
      end do
      return       
      end
c               
c   Copyright (c) 1990 by Dwight Meglan
c        
      logical*4 function GetPACompNum( Text,CSType,CompNum )
      implicit none

      include 'tel_name.inc'
      include 'tel_cons.inc'
                
      integer*4 CompNum,i,NumComp,CSType
      character Text*3
                   
      GetPACompNum= .false.
      i= 1
      NumComp= 3
      if ( CSType .eq. GCS_CST ) NumComp= 4
      do while ( (i .le. NumComp) .and. (.not. GetPACompNum) )
        if ( Text .eq. PitArmCompNames(i) ) then
          CompNum= i                                  
          GetPACompNum= .true.
        end if
        i= i + 1
      end do
      return       
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function GetSide( Text,side )
      implicit none

      integer*4 side
      character Text*3         

      GetSide= .false.
      if ( Text .eq. 'RT ' ) then
        side= 1
        GetSide= .true.
      else if ( Text .eq. 'LF ' ) then
        side= 2
        GetSide= .true.
      end if
      return
      end
c                      
c   Copyright (c) 1990 by Dwight Meglan
c                                 
      logical*4 function GetMrkNum( Line,Start,NumOK,Num,FileNum,MrkNum )
      implicit none  
              
      integer*4 Num,MrkNum,FileNum,i,Start
      logical*4 NumOK
      character Line*80,TempMrkName*4,MakeUpperCase*4

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
                 
      GetMrkNum= .false.
      if ( NumOK ) then
        if ( (Num .lt. 1) .or. (Num .gt. FD(FileNum).MP.num_mrk) ) then
          return
        else
          GetMrkNum= .true.
          MrkNum= Num
        end if
      else ! check for marker name
        i= 1                               
        do while ( (i .le. FD(FileNum).MP.num_mrk) .and. (.not. GetMrkNum) )
          TempMrkName= MakeUpperCase( FD(FileNum).MP.mrk_name(i) )
          if ( Line(Start:Start+3) .eq. TempMrkName ) then
            MrkNum= i
            GetMrkNum= .true.
          end if
          i= i + 1
        end do
      end if
      return
      end   
c
c   Copyright (c) 1990 by Dwight Meglan
c                                          
      logical*4 function GetSegMrkNum( Text,NumOK,Num,FileNum,SegNum,MrkNum )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'

      integer*4 Num,FileNum,SegNum,MrkNum,i
      logical*4 NumOK,MrkOK
      character Text*3              
                         
      MrkOK= .false.
      GetSegMrkNum= .false.
      if ( NumOK ) then     
        if ( (Num .lt. 1) .or. (Num .gt. FD(FileNum).MP.num_mrk) ) then
          return
        else
          MrkOK= .true.
        end if
      else ! check for marker name
        i= 1  
        do while ( (i .le. FD(FileNum).MP.num_mrk) .and. (.not. MrkOK) )
          if ( Text .eq. FD(FileNum).MP.mrk_name(i)(1:3) ) then
            Num= i
            MrkOK= .true.
          end if
          i= i + 1
        end do  
      end if
      if ( MrkOK ) then ! check whether marker is part of segment
        i= 1    
        do while ( (i .lt. FD(FileNum).SP(SegNum).num_mrk) .and.
     &             (.not. GetSegMrkNum) )
          if ( Num .eq. FD(FileNum).SP(SegNum).mrk_num(i) ) then
            MrkNum= i
            GetSegMrkNum= .true.
          end if
          i= i + 1
        end do                 
      end if
      return
      end
c              
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function GetSegNum( Line,SegText,Start,FileNum,SegNum,Side )
      implicit none
              
      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_name.inc'

      integer*4 SegNum,i,j,FileNum,Start,Side
      character Line*80,SegText*3
      logical*4 SegFound
                                  
      character SegNamesb(15)*3

      data SegNamesb / 'RFT','RCF','RTH','LFT','LCF',
     &                 'LTH','PLV','TRK','RLA','RUA',
     &                 'LLA','LUA','HED','RHD','LHD' /

      GetSegNum= .false.
      j= 1
      SegFound= .false.
      side= rt
      do while ( (j .le. FD(FileNum).GP.num_seg) .and. (.not. SegFound) )
        if ( (SegText .eq. SegNamesb(j)) .or.
     &       (Line(Start:Start+3) .eq. SegNames(j)) ) then
          SegFound= .true.
          if ( SegText(1:1) .eq. 'L' ) side= lf
        else                            
          j= j + 1      
        end if
      end do
      if ( SegFound ) then
        SegNum= j
        i= 1                                   
        do while ( (i .le. FD(FileNum).GP.num_seg) .and. (.not. GetSegNum) )
          if ( SegNum .eq. FD(FileNum).GP.seg_num(i) ) GetSegNum= .true.
          i= i + 1
        end do
        if ( GetSegNum ) SegNum= i - 1 ! this adjustment allows data to be read
      end if                           ! from ANZ files which have been compacted
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c                                              
      logical*4 function GetJntNum( Line,JntText,Start,FileNum,JntNum,Side )
      implicit none                          
                            
      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_name.inc'

      integer*4 JntNum,i,j,FileNum,Start,Side
      character JntText*3,Line*80
      logical*4 JntFound                     

      character JntNamesb(15)*3

      data JntNamesb / 'RAK','RKN','RHP','LAK','LKN',
     &                 'LHP','PVL','PVT','REL','RSH',
     &                 'LEL','LSH','NEC','RWR','LWR' /
                                       
      GetJntNum= .false.
      j= 1
      JntFound= .false.
      side= rt
      do while ( (j .le. FD(FileNum).GP.num_jnt) .and. (.not. JntFound) )
        if ( (JntText .eq. JntNamesb(j)) .or. 
     &       (Line(Start:Start+3) .eq. JntNames(j)) ) then
          JntFound= .true.
          if ( JntText(1:1) .eq. 'L' ) side= lf
        else
          j= j + 1                                  
        end if
      end do
      if ( JntFound ) then
        JntNum= j
        i= 1
        do while ( (i .le. FD(FileNum).GP.num_jnt) .and. (.not. GetJntNum) )
          if ( JntNum .eq. FD(FileNum).GP.jnt_num(i) ) GetJntNum= .true.
          i= i + 1
        end do
        if ( GetJntNum ) JntNum= i - 1 ! this adjustment allows data to be read
      end if                           ! from ANZ files which have been compacted
      return
      end               
c                   
c   Copyright (c) 1990 by Dwight Meglan
c                
      logical*4 function GetFileNum( NumOpt,OptNumOK,OptIntVal,
     &                               DefFileNum,FileNum )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'

      integer*4 NumOpt,OptIntVal(5),DefFileNum,FileNum,i
      logical*4 OptNumOK(5)

      GetFileNum= .false.
      if ( NumOpt .eq. 0 ) then
        GetFileNum= .true.
        FileNum= DefFileNum
      else
        i= 1
        do while ( (i .le. NumOpt) .and. (.not. GetFileNum) )
          if ( OptNumOK(i) ) then
            if ( (OptIntVal(i) .lt. 1) .or. 
     &           (OptIntVal(i) .gt. NumFileOpen) ) return
            FileNum= OptIntVal(i)
            GetFileNum= .true.
          end if
          i= i + 1
        end do                                 
      end if
      return        
      end
c
c   Copyright (c) 1990 by Dwight Meglan        
c
      subroutine DataMinMax( data,dataOK,numpnts,min,max )
      implicit none
                              
      integer*4 numpnts,i,j
      real*4    data(1),min,max
      logical*4 dataOK(1)

      j= 1
      do while ( (.not. dataOK(j)) .and. (j .le. numpnts) )
        j= j + 1
      end do
      if ( j .le. numpnts ) then
        min= data(j)
        max= data(j) 
        do i= j, numpnts
          if ( dataOK(i) ) then
            if ( data(i) .gt. max ) max= data(i)
            if ( data(i) .lt. min ) min= data(i)
          end if
        end do
      else
        max= 0.0
        min= 0.0
      end if
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function SegVarAvailable( VarNum,FileNum )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_name.inc'

      integer*4 VarNum,FileNum
                            
      SegVarAvailable= .false.
      if ( VarNum .eq. SPR_DATA ) then ! SPR
        SegVarAvailable= FD(FileNum).SF.Param         
      else if ( VarNum .eq. SPN_DATA ) then ! SPN
        SegVarAvailable= FD(FileNum).SF.Pos
      else if ( VarNum .eq. SMP_DATA ) then ! SMP
        SegVarAvailable= FD(FileNum).MF.Diagnostics
      else if ( VarNum .eq. SMD_DATA ) then ! SMD
        SegVarAvailable= FD(FileNum).MF.Diagnostics
      else if ( VarNum .eq. SVL_DATA ) then ! SVL     
        SegVarAvailable= FD(FileNum).SF.VelAcc
      else if ( VarNum .eq. SAC_DATA ) then ! SAC
        SegVarAvailable= FD(FileNum).SF.VelAcc
      else if ( (VarNum .ge. SKE_DATA) .and. 
     &          (VarNum .le. STE_DATA)       ) then ! Energy
        SegVarAvailable= FD(FileNum).SF.Energy
      else if ( VarNum .eq. SIS_DATA ) then ! SIS
        SegVarAvailable= FD(FileNum).SF.InstantScrew 
      else if ( VarNum .eq. SFS_DATA ) then ! SFS
        SegVarAvailable= FD(FileNum).SF.FiniteScrew 
      else if ( VarNum .eq. SMM_DATA ) then ! SMM
        SegVarAvailable= FD(FileNum).SF.Momentum
      else if ( VarNum .eq. SAN_DATA ) then ! SAN
        SegVarAvailable= FD(FileNum).SF.Angle
      else if ( (VarNum .ge. BKE_DATA) .and. 
     &          (VarNum .le. BTE_DATA)       ) then ! Body Energy
        SegVarAvailable= FD(FileNum).SF.Energy
      else if ( VarNum .eq. BCM_DATA ) then ! BCM  
        SegVarAvailable= FD(FileNum).SF.CntrMass
      else if ( VarNum .eq. BCV_DATA ) then ! BCMVel  
        SegVarAvailable= FD(FileNum).SF.BCMVel
      else if ( VarNum .eq. BMM_DATA ) then ! BMM
        SegVarAvailable= FD(FileNum).SF.Momentum
      else                    
        SegVarAvailable= .false.             
      end if                  
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function JntVarAvailable( VarNum,CSType,FileNum )
      implicit none
               
      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_name.inc'
                              
      integer*4 VarNum,FileNum,CSType

      JntVarAvailable= .false.         
      if ( VarNum .eq. JAN_DATA ) then
        if ( CSType .eq. JCS_CST ) then ! JAN/JCS
          JntVarAvailable= FD(FileNum).JF.AngJCS  
        else if ( CSType .eq. EUL_CST ) then ! JAN/EUL
          JntVarAvailable= FD(FileNum).JF.AngEUL
        end if
      else if ( VarNum .eq. JVL_DATA ) then
        if ( CSType .eq. JCS_CST ) then ! JVL/JCS
          JntVarAvailable= FD(FileNum).JF.VelAccJCS     
        else if ( CSType .eq. EUL_CST ) then ! JVL/EUL
          JntVarAvailable= FD(FileNum).JF.VelAccEUL
        end if
      else if ( VarNum .eq. JAC_DATA ) then
        if ( CSType .eq. JCS_CST ) then ! JAC/JCS
          JntVarAvailable= FD(FileNum).JF.VelAccJCS
        else if ( CSType .eq. EUL_CST ) then ! JAC/EUL
          JntVarAvailable= FD(FileNum).JF.VelAccEUL
        end if           
      else if ( VarNum .eq. JLD_DATA ) then ! JLD        
        JntVarAvailable= FD(FileNum).JF.Load
      else if ( VarNum .eq. JLL_DATA ) then ! JLL
        if ( FD(FileNum).JF.Load .and. 
     &       FD(FileNum).JF.LegSummed ) JntVarAvailable= .true.
      else if ( VarNum .eq. JWR_DATA ) then ! JWR
        JntVarAvailable= FD(FileNum).JF.Wrench
      else if ( VarNum .eq. JPW_DATA ) then ! JPW   
        JntVarAvailable= FD(FileNum).JF.Power
      else if ( VarNum .eq. JPL_DATA ) then ! JPL   
        if ( FD(FileNum).JF.Power .and. 
     &       FD(FileNum).JF.LegSummed  ) JntVarAvailable= .true.
      else if ( VarNum .eq. JIS_DATA ) then ! JIS
        JntVarAvailable= FD(FileNum).JF.InstantScrew
      else if ( VarNum .eq. JFS_DATA ) then ! JFS
        JntVarAvailable= FD(FileNum).JF.FiniteScrew
      else if ( VarNum .eq. JTR_DATA ) then ! JTR
        JntVarAvailable= FD(FileNum).JF.Translation
      else if ( VarNum .eq. JSA_DATA ) then ! JFS
        JntVarAvailable= FD(FileNum).JF.ScrewAngle
      else if ( VarNum .eq. JMA_DATA ) then ! Moment Arm
        JntVarAvailable= FD(FileNum).JF.MomentArm
      else if ( VarNum .eq. JWA_DATA ) then ! Wrench Arm
        JntVarAvailable= FD(FileNum).JF.WrenchArm
      else                                   
        JntVarAvailable= .false.          
      end if                  
      return             
      end
c                        
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function FrcVarAvailable( VarNum,CSType,FileNum )
      implicit none                       
       
      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_name.inc'
                   
      integer*4 VarNum,FileNum,CSType

      FrcVarAvailable= .false.
      if ( VarNum .eq. FPL_DATA ) then ! FPL
        FrcVarAvailable= FD(FileNum).FF.Read
      else if ( VarNum .eq. FFT_DATA ) then ! FFT
        FrcVarAvailable= FD(FileNum).FF.IndFt
      else if ( VarNum .eq. FCB_DATA ) then ! FCB
        FrcVarAvailable= FD(FileNum).FF.Adjusted
      else if ( VarNum .eq. FCP_DATA ) then ! FCP
        FrcVarAvailable= FD(FileNum).FF.CpGCS
      else if ( (VarNum .eq. FCF_DATA) .and. FD(FileNum).FF.IndFt ) then ! FCF
        if ( CSType .eq. GCS_CST ) then
          FrcVarAvailable= FD(FileNum).FF.CpGCS
        else if ( CSType .eq. LCS_CST ) then
          FrcVarAvailable= FD(FileNum).FF.CpLCS
        end if                            
      else if ( (VarNum .eq. FCC_DATA) .and. FD(FileNum).FF.Adjusted ) then ! FCC
        FrcVarAvailable= FD(FileNum).FF.CpGCS
      else if ( VarNum .eq. FWP_DATA ) then ! FWP
        FrcVarAvailable= FD(FileNum).FF.Wrench
      else if ( (VarNum .eq. FWF_DATA) .and. FD(FileNum).FF.IndFt ) then ! FWF
        FrcVarAvailable= FD(FileNum).FF.Wrench
      else if ( (VarNum .eq. FWC_DATA) .and. FD(FileNum).FF.Adjusted ) then ! FWC
        FrcVarAvailable= FD(FileNum).FF.Wrench
      else if ( VarNum .eq. FP1_DATA ) then ! FIP
        FrcVarAvailable= FD(FileNum).FF.Integral
      else if ( (VarNum .eq. FF1_DATA) .and. FD(FileNum).FF.IndFt ) then ! FIF
        FrcVarAvailable= FD(FileNum).FF.Integral
      else if ( (VarNum .eq. FC1_DATA) .and. FD(FileNum).FF.Adjusted ) then ! FIC
        FrcVarAvailable= FD(FileNum).FF.Integral
      else if ( VarNum .eq. FP2_DATA ) then ! FIP
        FrcVarAvailable= FD(FileNum).FF.Integral
      else if ( (VarNum .eq. FF2_DATA) .and. FD(FileNum).FF.IndFt ) then ! FIF
        FrcVarAvailable= FD(FileNum).FF.Integral
      else if ( (VarNum .eq. FC2_DATA) .and. FD(FileNum).FF.Adjusted ) then ! FIC
        FrcVarAvailable= FD(FileNum).FF.Integral
      else if ( VarNum .eq. FSI_DATA ) then ! FSI
        FrcVarAvailable= FD(FileNum).FF.Si
      else if ( VarNum .eq. PMA_DATA ) then
        FrcVarAvailable= FD(FileNum).FF.PitchMomArm
      else if ( VarNum .eq. PWA_DATA ) then
        FrcVarAvailable= FD(FileNum).FF.PitchWreArm
      else if ( VarNum .eq. FCV_DATA ) then
        FrcVarAvailable= FD(FileNum).FF.CpVelGCS
      else
        FrcVarAvailable= .false.
      end if                         
      return
      end   
c
c   Copyright (c) 1990 by Dwight Meglan
c
      logical*4 function RecVarAvailable( VarNum,CSType,FileNum )
      implicit none
       
      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_name.inc'
                   
      integer*4 VarNum,FileNum,CSType

      RecVarAvailable= .false.
      if ( ( (VarNum .eq. RFT_DATA) .or. (VarNum .eq. RCF_DATA) ) .and.
     &       FD(FileNum).FF.Rec )                     then ! RFT or RCF
        if ( CSType .eq. GCS_CST ) then         
          RecVarAvailable= FD(FileNum).FF.Rec
        else if ( CSType .eq. LCS_CST ) then    
          RecVarAvailable= FD(FileNum).FF.Rec
        else                         
          RecVarAvailable= .false.
        end if
      else if ( (VarNum .lt. RFT_DATA) .or. (VarNum .gt. RSI_DATA) ) then
        RecVarAvailable= .false.
      else ! RCB, RCC, or RSI
        RecVarAvailable= FD(FileNum).FF.Rec
      end if
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c                            
      subroutine NormalizeData( PltAxis,PltNum,GrNum,FileNum,error )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'
      include 'tel_name.inc'

      integer*4 GrNum,PltNum,FileNum,PltAxis,i
      logical*4 error                   

      real*4    LegLength,gravity

      data gravity / 9.81 /
                                    
      error= .true.                      
      if ( GROPT(GrNum).NormWt ) then                    
        if ( FD(FileNum).GP.Weight .lt. 1.0e-5 ) goto 1000
        do i= 1, PD(PltNum,GrNum).NumPnts
          if ( PltDataOK(i,PltNum,GrNum) ) PltData(i,PltAxis,PltNum,GrNum)=
     &      PltData(i,PltAxis,PltNum,GrNum)/(FD(FileNum).GP.Weight*gravity)
        end do
      else if ( GROPT(GrNum).NormWtHt ) then
        if ( FD(FileNum).GP.Weight .lt. 1.0e-5 ) goto 1000
        if ( FD(FileNum).GP.Height .lt. 1.0e-5 ) goto 1010
        do i= 1, PD(PltNum,GrNum).NumPnts
          if ( PltDataOK(i,PltNum,GrNum) ) PltData(i,PltAxis,PltNum,GrNum)=
     &      PltData(i,PltAxis,PltNum,GrNum)/
     &      (FD(FileNum).GP.Weight*FD(FileNum).GP.Height*gravity)
        end do                          
      else ! NormWtLeg
        if ( FD(FileNum).GP.Weight .lt. 1.0e-5 ) goto 1000
        if ( (FD(FileNum).SP(rtcf).length .lt. 1.0e-5) .or.
     &       (FD(FileNum).SP(rtth).length .lt. 1.0e-5) .or.
     &       (FD(FileNum).SP(lfcf).length .lt. 1.0e-5) .or.
     &       (FD(FileNum).SP(lfth).length .lt. 1.0e-5)      ) goto 1020
        LegLength= ( FD(FileNum).SP(rtcf).length +
     &               FD(FileNum).SP(rtth).length +
     &               FD(FileNum).SP(lfcf).length +
     &               FD(FileNum).SP(lfth).length )/4.0
        do i= 1, PD(PltNum,GrNum).NumPnts
          if ( PltDataOK(i,PltNum,GrNum) ) PltData(i,PltAxis,PltNum,GrNum)=
     &      PltData(i,PltAxis,PltNum,GrNum)/
     &      (FD(FileNum).GP.Weight*LegLength*gravity)
        end do                          
      end if                   
      error= .false.
      return
                      
1000  write(6,1005) GrNum,FileNum,FD(FileNum).Name
1005  format(' Error- Graph options for graph # ',i1,' are set to normalize the'/
     &       '        plot data by weight, but file # ',i1,' : ',a40/
     &       '        does not contain a valid weight')
      return

1010  write(6,1015) GrNum,FileNum,FD(FileNum).Name
1015  format(' Error- Graph options for graph # ',i1,' are set to normalize the'/
     &       '        plot data by height, but file # ',i1,' : ',a40/
     &       '        does not contain a valid height')
      return

1020  write(6,1025) GrNum,FileNum,FD(FileNum).Name
1025  format(' Error- Graph options for graph # ',i1,' are set to normalize the'/
     &       '        plot data by height, but file # ',i1,' : ',a40/
     &       '        does not contain valid leg segment lengths')
      return
      end 
c
c   Copyright (c) 1990 by Dwight Meglan   
c
      subroutine RemoveCMNDOpt( CMND,CmndNum,OptNum )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
 
      record /CmndLine/ CMND        
            
      integer*4 CmndNum,OptNum,j

      if ( OptNum .lt. MAX_NUM_CMND_OPT ) then
        do j= OptNum, CMND.NumOpt(CmndNum)
          CMND.OptText(j,CmndNum)=    CMND.OptText(j+1,CmndNum)
          CMND.OptNumOK(j,CmndNum)=   CMND.OptNumOK(j+1,CmndNum)
          CMND.OptIntVal(j,CmndNum)=  CMND.OptIntVal(j+1,CmndNum)
          CMND.OptRealVal(j,CmndNum)= CMND.OptRealVal(j+1,CmndNum)
          CMND.OptStart(j,CmndNum)=   CMND.OptStart(j+1,CmndNum)
          CMND.OptEnd(j,CmndNum)=     CMND.OptEnd(j+1,CmndNum)
        end do                      
      end if
      CMND.NumOpt(CmndNum)= CMND.NumOpt(CmndNum) - 1
      return                        
      end
c
c
c
      subroutine InterpretBlank( CMND,GrNum,error )            
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_grph.inc'
      include 'tel_name.inc' 

      record /CmndLine/    CMND
      integer*4 GrNum                  
      logical*4 error

      integer*4 i
                                           
c
c     Check over commands in command line- Only available commands are:
c     TITle SUBtitle DATe NAMe FILe/# TimeDistance1 TimeDistance2
c                               
      error= .true.
      GD(GrNum).ShowBlankTitle=    .false.
      GD(GrNum).ShowBlankSubtitle= .false.
      GD(GrNum).ShowBlankDate=     .false.
      GD(GrNum).ShowBlankName=     .false.
      GD(GrNum).ShowBlankFilename= .false.
      GD(GrNum).ShowBlankFileNum=  1
      GD(GrNum).ShowBlankTD1= .false.
      GD(GrNum).ShowBlankTD2= .false.
      do i= 2, CMND.NumCmnd     
        if ( CMND.CmndText(i) .eq. 'TIT' ) then
          GD(GrNum).ShowBlankTitle= .true.
        else if ( CMND.CmndText(i) .eq. 'SUB' ) then     
          GD(GrNum).ShowBlankSubtitle= .true.
        else if ( CMND.CmndText(i) .eq. 'DAT' ) then
          GD(GrNum).ShowBlankDate= .true.
        else if ( CMND.CmndText(i) .eq. 'NAM' ) then
          GD(GrNum).ShowBlankName= .true.
        else if ( CMND.CmndText(i) .eq. 'FIL' ) then
          if ( CMND.NumOpt(i) .eq. 0 ) then
            GD(GrNum).ShowBlankFilename= .true.
            GD(GrNum).ShowBlankFileNum= 1
          else                  
            if ( .not. CMND.OptNumOK(1,i) ) goto 1000
            if ( (CMND.OptIntVal(1,i) .gt. NumFileOpen) .or.
     &           (CMND.OptIntVal(1,i) .lt. 1)                ) goto 1010
            GD(GrNum).ShowBlankFileNum= CMND.OptIntVal(1,i)           
            GD(GrNum).ShowBlankFilename= .true.
          end if
        else if ( CMND.CmndText(i) .eq. 'TD1' ) then
          if ( CMND.NumOpt(i) .eq. 0 ) then
            GD(GrNum).ShowBlankTD1Fn= 1
          else                  
            if ( .not. CMND.OptNumOK(1,i) ) goto 1000
            if ( (CMND.OptIntVal(1,i) .gt. NumFileOpen) .or.
     &           (CMND.OptIntVal(1,i) .lt. 1)                ) goto 1010
            GD(GrNum).ShowBlankTD1Fn= CMND.OptIntVal(1,i)           
          end if
          if ( .not. FD(GD(GrNum).ShowBlankTD1Fn).CF.Statistics ) goto 1030
          GD(GrNum).ShowBlankTD1= .true.
        else if ( CMND.CmndText(i) .eq. 'TD2' ) then
          if ( CMND.NumOpt(i) .eq. 0 ) then
            GD(GrNum).ShowBlankTD2Fn= 1
          else                  
            if ( .not. CMND.OptNumOK(1,i) ) goto 1000
            if ( (CMND.OptIntVal(1,i) .gt. NumFileOpen) .or.
     &           (CMND.OptIntVal(1,i) .lt. 1)                ) goto 1010
            GD(GrNum).ShowBlankTD2Fn= CMND.OptIntVal(1,i)           
          end if
          if ( .not. FD(GD(GrNum).ShowBlankTD2Fn).CF.Statistics ) goto 1030
          GD(GrNum).ShowBlankTD2= .true.
        else
          goto 1020
        end if
      end do                                                     
      error= .false.
      return
         
1000  write(6,1005) CMND.OptText(1,i)
1005  format(' Error- ',a3,' is not a valid file number')
      return       

1010  write(6,1015) CMND.OptIntVal,NumFileOpen
1015  format(' Error- ',i3,' is not a valid file number'/
     &       '        Valid file numbers are 1 thru ',i2)
      return       

1020  write(6,1025) CMND.CmndText(i)
1025  format(' Error- ',a3,' is not a valid blank graph command'/
     &       '        Valid commands are: TITle SUBtitle   DATe '/
     &       '                            NAMe  FILename/#'/
     &       '                            TimeDistance1 TimeDistance2')
      return       

1030  write(6,1035) FD(GD(GrNum).ShowBlankTD1Fn).Name
1035  format(' Error- ',a40,' does not contain distance information')
      return
      end                                     

