c 
c   Copyright (c) 1990 by Dwight Meglan             
c                                       
      subroutine SetOptions( CMND,MACRO )
      implicit none

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

      include 'vogle.fi'
                                 
      record /CmndLine/    CMND
      record /MacroStuff/  MACRO

      integer*4 NumGrOpt,NumTdOpt,GrNum,i,j,k,x,y,axis,start,MaxGrOptOnOff,
     &          ierr
      real*4    temp
      logical*4 OptOK,UpdateAllGROPT,UpdateAllTDOPT
      character GrOptType(35)*3,TdOptType(17)*3,blank80*80,blank20*20,
     &          newprintfile*40
                
      data NumGrOpt,MaxGrOptOnOff,x,y / 35,25,1,2 /
      data GrOptType / 'CYC','RAA','PRI','SCR','LGD','MLG','EVE','PCT','ALI',
     &                 'LIN','SYM','GRL','MGL','NWT','NWH','NWL','XZL','YZL',
     &                 'PFZ','SAS','FGE','FOT','FPO','PST','MSC',
     &                 'DEF','LGP','DIV',
     &                 'FON','MLT','MGT','TIT','SUB','XTI','YTI' /
                                
      do i= 1, 80
        blank80(i:i)= ' '
      end do                                 
      do i= 1, 20
        blank20(i:i)= ' '
      end do
      if ( CMND.CmndText(2) .eq. 'GRA' ) then ! graph option             
        UpDateAllGROPT= .false.
        if ( CMND.NumOpt(2) .gt. 0 ) then ! check for graph #
          if ( CMND.NumOpt(2) .gt. 1 ) goto 1020 ! error
          if ( CMND.OptText(1,2) .eq. 'ALL' ) then
            UpDateAllGROPT= .true.
          else if ( CMND.OptNumOK(1,2) ) then
            if ( (CMND.OptIntVal(1,2) .gt. MAX_CHART) .or.
     &           (CMND.OptIntVal(1,2) .lt. 1)      ) goto 1030 ! error
            GrNum= CMND.OptIntVal(1,2)   
          else
            goto 1040 ! error- bad option
          end if
        else
          GrNum= 1
c          write(6,10)
c10        format(' Graph option will apply to graph #1 only')          
        end if                   
c
c      Before checking other options, check for the special case of resetting
c      the options of a graph or all graphs
c                                            
        if ( CMND.CmndText(3) .eq. 'RES' ) then 
          call ResetGrOpt( GrNum,UpDateAllGROPT )
          return
        end if                          
        OptOK= .false.                      
        i= 0
        do while ( (.not. OptOK) .and. (i .lt. NumGrOpt) )
          i= i + 1
          if ( CMND.CmndText(3) .eq. GrOptType(i) ) OptOK= .true.
        end do
c
c       Set the appropriate graph option
c                             
        if ( .not. OptOK ) goto 1010 ! error
        if ( (CMND.NumCmnd .lt. 4) .and.  
     &       (i .lt. MaxGrOptOnOff+5)     ) goto 1000 ! error
        if ( (i .le. MaxGrOptOnOff-1) .or. 
     &       ((i .eq. MaxGrOptOnOff) .and. 
     &        (CMND.NumCmnd .eq. 4))         ) then ! option will be
          if ( CMND.CmndText(4) .eq. 'ON ' ) then   ! an on/off flag
            if ( UpdateAllGROPT ) then
              do j= 1, MAX_CHART
                GROPT(j).Flag(i)= .true.
                if ( i .eq. 4 ) then
                  GROPT(j).Print= .false. ! turn print off when screen on
                  CHOPT.Print=    .false. ! force chart also
                  CHOPT.Screen=   .true.
                else if ( i .eq. 14 ) then
                  GROPT(j).Flag(15)= .false. ! make sure only
                  GROPT(j).Flag(16)= .false. ! one type of norm is active
                else if ( i .eq. 15 ) then
                  GROPT(j).Flag(14)= .false. 
                  GROPT(j).Flag(16)= .false. 
                else if ( i .eq. 16 ) then
                  GROPT(j).Flag(14)= .false. 
                  GROPT(j).Flag(15)= .false. 
                end if
              end do                                       
            else
              GROPT(GrNum).Flag(i)= .true.
              if ( i .eq. 4 ) then
                GROPT(GrNum).Print= .false. ! turn print off when screen on
                CHOPT.Print=        .false. ! force chart also
                CHOPT.Screen=       .true.
              else if ( i .eq. 14 ) then
                GROPT(GrNum).Flag(15)= .false. ! make sure only
                GROPT(GrNum).Flag(16)= .false. ! one type of norm is active
              else if ( i .eq. 15 ) then
                GROPT(GrNum).Flag(14)= .false. 
                GROPT(GrNum).Flag(16)= .false. 
              else if ( i .eq. 16 ) then
                GROPT(GrNum).Flag(14)= .false. 
                GROPT(GrNum).Flag(15)= .false. 
              end if
            end if
          else if ( CMND.CmndText(4) .eq. 'OFF' ) then
            if ( UpdateAllGROPT ) then
              do j= 1, MAX_CHART
                GROPT(j).Flag(i)= .false.             
                if ( i .eq. 4 ) then
                  GROPT(j).Print= .true. ! No Screen then must Print
                  CHOPT.Print=    .true.
                  CHOPT.Screen=   .false.
                end if
              end do                           
            else
              GROPT(GrNum).Flag(i)= .false.    
              if ( i .eq. 4 ) then
                GROPT(GrNum).Print= .true. ! No Screen then must print
                CHOPT.Print= .true.        ! Force strip chart
                CHOPT.Screen= .false.
               end if
            end if                                     
          else                     
            goto 1060 ! error- bad command
          end if
                                         
        else if ( i .eq. MaxGrOptOnOff ) then ! Manual SCale
          if ( CMND.NumCmnd .ne. 7 ) goto 1070 ! error- not enough entries
          do j= 4, 7     
            if ( .not. CMND.CmndNumOK(j) ) goto 1080 ! error- not a number
          end do
          if ( UpdateAllGROPT ) then                 
            do j= 1, MAX_CHART
              GROPT(j).ManMin(x)= CMND.CmndRealVal(4)
              GROPT(j).ManMax(x)= CMND.CmndRealVal(5)
              GROPT(j).ManMin(y)= CMND.CmndRealVal(6)
              GROPT(j).ManMax(y)= CMND.CmndRealVal(7)
              do k= x, y
                if ( GROPT(j).ManMin(k) .gt. GROPT(j).ManMax(k) ) 
     &            call swapr( GROPT(j).ManMin(k),GROPT(j).ManMax(k) )
              end do ! k
            end do ! j
          else          
            GROPT(GrNum).ManMin(x)= CMND.CmndRealVal(4)
            GROPT(GrNum).ManMax(x)= CMND.CmndRealVal(5)
            GROPT(GrNum).ManMin(y)= CMND.CmndRealVal(6)
            GROPT(GrNum).ManMax(y)= CMND.CmndRealVal(7)
            do k= x, y
              if ( GROPT(GrNum).ManMin(k) .gt. GROPT(GrNum).ManMax(k) )
     &          call swapr( GROPT(GrNum).ManMin(k),GROPT(GrNum).ManMax(k) )
            end do ! k     
          end if

        else if ( i .eq. MaxGrOptOnOff+1 ) then ! set default file number
          if ( .not. CMND.CmndNumOK(4) ) goto 1090 ! error- bad number
          if ( (CMND.CmndIntVal(4) .gt. NumFileOpen) .or.
     &         (CMND.CmndIntVal(4) .lt. 1)       ) goto 2000 ! error
          if ( UpdateAllGROPT ) then
            do j= 1, MAX_CHART
              GROPT(j).DefFile= CMND.CmndIntVal(4)
            end do
          else             
            GROPT(GrNum).DefFile= CMND.CmndIntVal(4)
          end if

        else if ( i .eq. MaxGrOptOnOff+2 ) then ! set legend position
          if ( .not. CMND.CmndNumOK(4) ) goto 2010 ! error- bad number
          if ( (CMND.CmndIntVal(4) .gt. 9) .or.
     &         (CMND.CmndIntVal(4) .lt. 1)      ) goto 2020 ! error
          if ( UpdateAllGROPT ) then    
            do j= 1, MAX_CHART           
              GROPT(j).LgndPosNum= CMND.CmndIntVal(4)
            end do
          else                          
            GROPT(GrNum).LgndPosNum= CMND.CmndIntVal(4)
          end if

        else if ( i .eq. MaxGrOptOnOff+3 ) then ! set number of divisions on axis
          if ( CMND.NumCmnd .ne. 5 ) goto 2030 ! error
          if ( CMND.CmndText(4) .eq. 'X  ' ) then
            axis= x
          else if ( CMND.CmndText(4) .eq. 'Y  ' ) then
            axis= y        
          else
            goto 2040 ! error- bad axis name
          end if
          if ( .not. CMND.CmndNumOK(5) ) goto 2050 ! error- bad number
          if ( (CMND.CmndIntVal(5) .lt. 2) .or.
     &         (CMND.CmndIntVal(5) .gt. 20)      ) goto 2060 ! error
          if ( UpdateAllGROPT ) then
            do j= 1, MAX_CHART
              GROPT(j).NumDiv(axis)= CMND.CmndIntVal(5)
            end do
          else                          
            GROPT(GrNum).NumDiv(axis)= CMND.CmndIntVal(5)
          end if
 
        else if ( i .eq. MaxGrOptOnOff+4 ) then ! set graph font
          if ( .not. CMND.CmndNumOK(4) ) goto 2080 ! error- bad number
          if ( (CMND.CmndIntVal(4) .lt. 1) .or.
     &         (CMND.CmndIntVal(4) .gt. 30)      ) goto 2080 ! error
          if ( UpdateAllGROPT ) then    
            do j= 1, MAX_CHART
              GROPT(j).Font= CMND.CmndIntVal(4)
            end do          
          else                          
            GROPT(GrNum).Font= CMND.CmndIntVal(4)
          end if
 
        else if ( i .eq. MaxGrOptOnOff+5 ) then ! set legend text
c          if ( CMND.NumCmnd .ne. 5 ) goto 2090
          if ( .not. CMND.CmndNumOK(4) ) goto 3000
          if ( (CMND.CmndIntVal(4) .lt. 1) .or.     
     &         (CMND.CmndIntVal(4) .gt. MAX_PLOT) ) goto 3000
          if ( UpdateAllGROPT ) then
            if ( (CMND.CmndText(5) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 4)               ) then
              do j= 1, MAX_CHART      
                GROPT(j).ManLgnd(CMND.CmndIntVal(4))= blank20
              end do
            else
              do j= 1, MAX_CHART      
                GROPT(j).ManLgnd(CMND.CmndIntVal(4))= 
     &            CMND.Text(1)(CMND.CmndEnd(4)+1:CMND.CmndEnd(4)+21)
              end do
            end if
          else             
            if ( (CMND.CmndText(5) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 4)               ) then
              GROPT(GrNum).ManLgnd(CMND.CmndIntVal(4))= blank20
            else
              GROPT(GrNum).ManLgnd(CMND.CmndIntVal(4))= 
     &          CMND.Text(1)(CMND.CmndEnd(4)+1:CMND.CmndEnd(4)+21)
            end if                      
          end if

        else if ( i .eq. MaxGrOptOnOff+6 ) then ! set graph name text
          if ( UpdateAllGROPT ) then
            if ( (CMND.CmndText(4) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 3)               ) then
              do j= 1, MAX_CHART     
                GROPT(j).ManGrLabel= blank20
              end do         
            else
              do j= 1, MAX_CHART     
                GROPT(j).ManGrLabel= 
     &            CMND.Text(1)(CMND.CmndEnd(3)+1:CMND.CmndEnd(3)+21)
              end do         
            end if
          else             
            if ( (CMND.CmndText(4) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 3)               ) then
              GROPT(GrNum).ManGrLabel= blank20
            else
              GROPT(GrNum).ManGrLabel= 
     &          CMND.Text(1)(CMND.CmndEnd(3)+1:CMND.CmndEnd(3)+21)
            end if
          end if

        else if ( i .eq. MaxGrOptOnOff+7 ) then ! set graph title text
          start= CMND.CmndEnd(3)+1      
          if ( UpdateAllGROPT ) then
            if ( (CMND.CmndText(4) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 3)               ) then
              do j= 1, MAX_CHART   
                GD(j).Title= blank80
              end do
            else
              do j= 1, MAX_CHART   
                GD(j).Title= CMND.Text(1)(start:80)
              end do
            end if
          else
            if ( (CMND.CmndText(4) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 3)               ) then
              GD(GrNum).Title= blank80
            else
              GD(GrNum).Title= CMND.Text(1)(start:80)
            end if
          end if           

        else if ( i .eq. MaxGrOptOnOff+8 ) then ! assign graph subtitle
          start= CMND.CmndEnd(3)+1
          if ( UpdateAllGROPT ) then    
            if ( (CMND.CmndText(4) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 3)               ) then
              do j= 1, MAX_CHART
                GD(j).SubTitle= blank80
              end do
            else
              do j= 1, MAX_CHART
                GD(j).SubTitle= CMND.Text(1)(start:80)
              end do
            end if
          else
            if ( (CMND.CmndText(4) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 3)               ) then
              GD(GrNum).SubTitle= blank80
            else
              GD(GrNum).SubTitle= CMND.Text(1)(start:80)
            end if
          end if           

        else if ( i .eq. MaxGrOptOnOff+9 ) then ! assign graph x axis title
          start= CMND.CmndEnd(3)+1
          if ( UpdateAllGROPT ) then    
            if ( (CMND.CmndText(4) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 3)               ) then
              do j= 1, MAX_CHART
                GD(j).Xtitle= blank80
              end do
            else
              do j= 1, MAX_CHART
                GD(j).Xtitle= CMND.Text(1)(start:80)
              end do
            end if
          else
            if ( (CMND.CmndText(4) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 3)               ) then
              GD(GrNum).Xtitle= blank80
            else
              GD(GrNum).Xtitle= CMND.Text(1)(start:80)
            end if
          end if           

        else if ( i .eq. MaxGrOptOnOff+10 ) then ! assign graph y axis title
          start= CMND.CmndEnd(3)+1
          if ( UpdateAllGROPT ) then    
            if ( (CMND.CmndText(4) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 3)               ) then
              do j= 1, MAX_CHART
                GD(j).Ytitle= blank80
              end do
            else
              do j= 1, MAX_CHART
                GD(j).Ytitle= CMND.Text(1)(start:80)
              end do
            end if
          else
            if ( (CMND.CmndText(4) .eq. '***') .or.
     &           (CMND.NumCmnd .eq. 3)               ) then
              GD(GrNum).Ytitle= blank80
            else
              GD(GrNum).Ytitle= CMND.Text(1)(start:80)
            end if
          end if
        end if ! which graph option

      else if ( CMND.CmndText(2) .eq. '3DV' ) then
        write(6,100)
100     format(' 3D display options are not implemented yet')

      else if ( CMND.CmndText(2) .eq. 'SCH' ) then
        call SetChartOption( CMND )

      else if ( CMND.CmndText(2) .eq. 'MAC' ) then
        if ( CMND.CmndText(3) .eq. 'ECH' ) then
          if ( CMND.CmndText(4) .eq. 'ON ' ) then   ! an on/off flag
            Macro.Echo= .true.
          else if ( CMND.CmndText(4) .eq. 'OFF' ) then
            Macro.Echo= .false.
          else
210         write(6,215) CMND.CmndText(4)
215         format(' Error- ',a3,' is not valid.'/
     &             '        Only ON or OFF are allowed.')
          end if
        else
          write(6,200) CMND.CmndText(3)
200       format('Error- ',a3,' is not a valid Macro options'/
     &           '       The only valid option right now is ECHo ON/OFF')
        end if

      else if ( CMND.CmndText(2) .eq. 'PRI' ) then
         do i= 1, 40
            newprintfile(i:i)= ' '
         end do
         j= 1
         do i= CMND.CmndStart(3), CMND.CmndEnd(3)
            newprintfile(j:j)= CMND.Text(1)(i:i)
            j= j+1
         end do
         ierr= voutput(newprintfile(1:lentrim(newprintfile))//char(0)) 
         if ( ierr .eq. 0 ) then
            write(6,310) newprintfile
 310        format(' Error- Could not open new file for printer output'/
     &             '        File: ',a40)
         end if

      else 
        goto 2070 ! error
      end if             
      return       

1000  write(6,1005)
1005  format(' Error- There must be at least 4 entries in the option command')
      return

1010  write(6,1015) CMND.CmndText(3),(GrOptType(i),i=1,30)
1015  format(' Error- ',a3,' is not a valid graph option'/
     &       '        Valid options are: RESet '/
     &       5(27x,7(a3,1x)/) )            
      return

1020  write(6,1025) MAX_GRAPH
1025  format(' Error- More than option indicating the graph number has been'/
     &       '        given.  Only one option is allowed (1-',i1,'all)')
      return
                           
1030  write(6,1035) CMND.OptIntVal(1,2),MAX_GRAPH
1035  format(' Error- Graph number ',i5', is indicated but only graphs 1-',i1/
     &       '        are valid.')
      return
                                 
1040  write(6,1045) CMND.OptText(1,2)
1045  format(' Error- ',a3,' is not valid indictor of which graph(s) is'/
     &       '        to have its options changed. 1-6 and all are valid.')
      return

1060  write(6,1065) CMND.CmndText(4)
1065  format(' Error- ',a3,' is not a valid entry for changing the graph'/
     &       '        option flag.  Only on and off are valid.')
      return

1070  write(6,1075)
1075  format(' Error- There must be 7 entries in the option command'/
     &       '        if the axis scaling is to manually specified'/
     &       '        opt gra msc xmin xmax ymin ymax')
      return

1080  write(6,1085) CMND.CmndText(j)
1085  format(' Error- ',a3,' is not a valid number')
      return

1090  write(6,1095) CMND.CmndText(4)
1095  format(' Error- ',a3,' is not a valid file number')
      return

2000  write(6,2005) CMND.CmndIntVal(4),NumFileOpen
2005  format(' Error- ',i5,' is not a valid file number'/
     &       '        Valid file numbers are from 1 to ',i1)
      return

2010  write(6,2015) CMND.CmndText(4)
2015  format(' Error- ',a3,' is not a valid number')
      return
 
2020  write(6,2025) CMND.CmndIntVal(4)
2025  format(' Error- ',i5,' is not a valid legend position number'/
     &       '        Valid position numbers are from 1 to 9')
      return

2030  write(6,2035) 
2035  format(' Error- There must 5 command entries to change the number'/
     &       '        of graph axis divisions:  opt gra div x/y 2-20')
      return                         

2040  write(6,2045) CMND.CmndText(4)
2045  format(' Error- ',a3,' is not a valid axis name'/
     &       '        Valid axis names are x and y')
      return

2050  write(6,2055) CMND.CmndText(5)
2055  format(' Error- ',a3,' is not a valid number')
      return
 
2060  write(6,2065) CMND.CmndIntVal(5)
2065  format(' Error- ',i5,' is not a valid number of axis divisions'/
     &       '        The number of divisions must be between 2 and 20')
      return

2070  write(6,2075) CMND.CmndText(2)
2075  format(' Error- ',a3,' is not a valid option'/
     &       '        Valid options are: GRAph SCHart MACro PRInt')
      return

2080  write(6,2085) CMND.CmndText(4)
2085  format(' Error- ',a3,' is not a valid font number'/
     &       '        Valid font #''s are from 1 to 30')
      return

2090  write(6,2095) 
2095  format(' Error- There must be at least 5 entries to set a plot legend'/
     &       '        Ex: OPT GRA MLT 1 This a test legend...')
      return

3000  write(6,3005) CMND.CmndText(4),MAX_PLOT
3005  format(' Error- ',a3,' is not a valid plot number'/
     &       '        Valid plot #''s are from 1 to ',i2)
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c        
      subroutine ResetGrOpt( GrNum,AllGraphs )
      implicit none

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

      integer*4 GrNum,i,j
      logical*4 AllGraphs
                           
      if ( AllGraphs ) then
        do i= 1, MAX_CHART
          GROPT(i).CycleClip=       .false.
          GROPT(i).RemAvgAng=       .false.
c          GROPT(i).Print=           .false.
c          GROPT(i).Screen=          .true.
          GROPT(i).LgndFlg=         .true.
          GROPT(i).ManLgndFlg=      .false.
          GROPT(i).EventOn=         .true.
          GROPT(i).PctCycleLn=      .true.
          GROPT(i).AlignSides=      .false.
          GROPT(i).LnFlg=           .true.
          GROPT(i).SymFlg=          .true.
          GROPT(i).GrLabelFlg=      .true.
          GROPT(i).ManGrLabelFlg=   .false.
          GROPT(i).NormWt=          .false.
          GROPT(i).NormWtHt=        .false.
          GROPT(i).NormWtLeg=       .false.
          GROPT(i).XZeroLine=       .true.
          GROPT(i).YZeroLine=       .true.
          GROPT(i).PositiveFz=      .true.
          GROPT(i).SimpleAutoScale= .false.
          GROPT(i).FirstGaitEvent=  .true.
          GROPT(i).ShowFtOutLine=   .true.
          GROPT(i).ShowFpOutLine=   .true.
          GROPT(i).UsePostPrint=    .false.
          GROPT(i).ManScale=        .false.
          GROPT(i).DefFile=    1
          GROPT(i).LgndPosNum= 1
          GROPT(i).Font=       1
          do j= 1, MAX_PLOT
            GROPT(i).ManLgnd(j)(1:14)= 'Legend entry '//char(j)
          end do
          do j= 1, 2
            GROPT(i).ManMin(j)= 0.0
            GROPT(i).ManMax(j)= 1.0
            GROPT(i).NumDiv(j)= 5
          end do
          do j= 1, 80
            GD(i).Title(j:j)= ' '
            GD(i).Subtitle(j:j)= ' '
          end do
          GD(i).Title(1:13)=   'Title not set'
          GD(i).Subtitle(1:8)= 'Subtitle'
          do j= 1, 40
            GD(i).Xtitle(j:j)= ' '
            GD(i).Ytitle(j:j)= ' '
            GD(i).GrLabel(j:j)= ' '
            GROPT(i).ManGrLabel(j:j)= ' '
          end do          
          GD(i).Xtitle(1:12)=   'X axis label'        
          GD(i).Ytitle(1:12)=   'Y axis label'
          GROPT(i).ManGrLabel(1:14)=  'John Q. Public'
        end do
      else
        GROPT(GrNum).CycleClip=     .false.
        GROPT(GrNum).RemAvgAng=     .false.
c        GROPT(GrNum).Print=         .false.
c        GROPT(GrNum).Screen=        .true.
        GROPT(GrNum).LgndFlg=       .true.
        GROPT(GrNum).ManLgndFlg=    .false.
        GROPT(GrNum).EventOn=       .true.
        GROPT(GrNum).PctCycleLn=    .true.
        GROPT(GrNum).AlignSides=    .false.
        GROPT(GrNum).LnFlg=         .true.
        GROPT(GrNum).SymFlg=        .true.
        GROPT(GrNum).GrLabelFlg=    .true.
        GROPT(GrNum).ManGrLabelFlg= .false.
        GROPT(GrNum).NormWt=        .false.
        GROPT(GrNum).NormWtHt=      .false.
        GROPT(GrNum).NormWtLeg=     .false.
        GROPT(GrNum).XZeroLine=     .true.
        GROPT(GrNum).YZeroLine=     .true.
        GROPT(GrNum).PositiveFz=    .true.
        GROPT(GrNum).SimpleAutoScale= .false.
        GROPT(GrNum).FirstGaitEvent=  .true.
        GROPT(GrNum).ShowFtOutLine= .true.
        GROPT(GrNum).ShowFpOutLine= .true.
        GROPT(GrNum).ManScale=      .false.
        GROPT(GrNum).DefFile=    1
        GROPT(GrNum).LgndPosNum= 1
        GROPT(GrNum).Font=       1
        do j= 1, MAX_PLOT
          GROPT(GrNum).ManLgnd(j)= 'Legend entry '//char(j)
        end do
        do j= 1, 2
          GROPT(GrNum).ManMin(j)= 0.0
          GROPT(GrNum).ManMax(j)= 1.0
          GROPT(GrNum).NumDiv(j)= 5
        end do
        do j= 1, 80
          GD(GrNum).Title(j:j)= ' '
          GD(GrNum).Subtitle(j:j)= ' '
        end do
        GD(GrNum).Title(1:13)=   'Title not set'
        GD(GrNum).Subtitle(1:8)= 'Subtitle'
        do j= 1, 40
            GD(GrNum).Xtitle(j:j)= ' '
            GD(GrNum).Ytitle(j:j)= ' '
            GD(GrNum).GrLabel(j:j)= ' '
            GROPT(GrNum).ManGrLabel(j:j)= ' '
        end do          
        GD(GrNum).Xtitle(1:12)=   'X axis label'        
        GD(GrNum).Ytitle(1:12)=   'Y axis label'
        GROPT(GrNum).ManGrLabel(1:14)=  'John Q. Public'
      end if
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      subroutine SetChartOption( CMND )
      implicit none

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

      record /CmndLine/    CMND

      integer*4 NumChOpt,x,y,i,j,MaxSchOptOnOff
      logical*4 OptOK,SwitchOK,SwitchON
      character ChOptType(13)*3,blank40*40

      data NumChOpt,MaxSchOptOnOff,x,y / 13,9,1,2 /

      data ChOptType / 'EVE','TIT','LAB','MLB','MNX','SAS','PRI','SCR','PST',
     &                 'SUB','XTI','XDV','FON' /

c           
c      Before checking other options, check for the special case of resetting
c      the options of the chart
c
      if ( CMND.CmndText(3) .eq. 'RES' ) then 
        call ResetSChartOpt
        return
      end if                          
      OptOK= .false.                      
      i= 0
      do while ( (.not. OptOK) .and. (i .lt. NumChOpt) )
        i= i + 1
        if ( CMND.CmndText(3) .eq. ChOptType(i) ) OptOK= .true.
      end do                 
c               
c     Set the appropriate chart option
c
      if ( .not. OptOK ) goto 1010 ! error
      if ( (CMND.NumCmnd .lt. 4) .and. 
     &     (i .ne. 2) .and. (i .ne. 4) .and.
     &     (i .ne. 9) .and. (i .ne. 10)       ) goto 1000 ! error
      do j= 1, 40
        blank40(j:j)= ' ' 
      end do           
      SwitchOK= .false.   
      SwitchON= .false.
      if ( i .le. MaxSchOptOnOff ) then            ! option might be an
        if ( CMND.CmndText(4) .eq. 'ON ' ) then    ! on/off switch
          SwitchON= .true.
          SwitchOK= .true.      
        else if ( CMND.CmndText(4) .eq. 'OFF' ) then
          SwitchON= .false.
          SwitchOK= .true.
        end if 
      end if
      if ( i .eq. 1 ) then  ! EVEnt
        if ( .not. SwitchOK ) goto 1020 ! error
        CHOPT.EventOn= SwitchON
                                    
      else if ( i .eq. 2 ) then ! TITle
        if ( SwitchOK ) then        
          CHOPT.DisplayTitle= SwitchON   
        else
          if ( (CMND.CmndText(4) .eq. '***') .or. (CMND.NumCmnd .eq. 3) ) then
              CHOPT.Title= blank40
          else
            CHOPT.Title= CMND.Text(1)(CMND.CmndEnd(3)+1:CMND.CmndEnd(3)+41)
          end if       
        end if                    

      else if ( i .eq. 3 ) then ! LABel
        if ( .not. SwitchOK ) goto 1030 ! error
        CHOPT.DisplayLabel= SwitchON
                   
      else if ( i .eq. 4 ) then ! ManualLaBel
        if ( SwitchOK ) then
          CHOPT.ManLabel= SwitchON
        else
          if ( (CMND.CmndText(4) .eq. '***') .or. (CMND.NumCmnd .eq. 3) ) then
            CHOPT.ChartLabel= blank40
          else
            CHOPT.ChartLabel= CMND.Text(1)(CMND.CmndEnd(3)+1:CMND.CmndEnd(3)+41)
          end if
        end if

      else if ( i .eq. 5 ) then ! MaNual X axis scale
        if ( SwitchOK ) then
          CHOPT.ManXaxis= SwitchON
        else
          if ( CMND.NumCmnd .lt. 5 ) goto 1040 ! error
          if ( .not. CMND.CmndNumOK(4) ) goto 1050 ! error
          if ( .not. CMND.CmndNumOK(5) ) goto 1060 ! error
          CHOPT.Xmin= CMND.CmndRealVal(4)
          CHOPT.Xmax= CMND.CmndRealVal(5)
          if ( CHOPT.Xmin .gt. CHOPT.Xmax ) call swapr( CHOPT.Xmin,CHOPT.Xmax )
        end if                   
                
      else if ( i .eq. 6 ) then ! SimpleAutoScale
        if ( .not. SwitchOK ) goto 1110 ! error
        CHOPT.SimpleAutoScale= SwitchON

      else if ( i .eq. 7 ) then ! PRInt
        if ( .not. SwitchOK ) goto 1100 ! error
        CHOPT.Print= SwitchON

      else if ( i .eq. 8 ) then ! SCReen
        if ( .not. SwitchOK ) goto 1070 ! error
        if ( .not. SwitchON ) then
          CHOPT.Print=  .true.
          CHOPT.Screen= .false.       
        else
          CHOPT.Screen= .true.
          CHOPT.Print=  .false.
        end if
                                                   
      else if ( i .eq. 9 ) then ! PostScript Printer
        if ( .not. SwitchOK ) goto 1100 ! error
        CHOPT.UsePostPrint= SwitchON

      else if ( i .eq. 10 ) then ! SUBtitle
        if ( (CMND.CmndText(4) .eq. '***') .or. (CMND.NumCmnd .eq. 3) ) then
          CHOPT.SubTitle= blank40
        else
          CHOPT.SubTitle= CMND.Text(1)(CMND.CmndEnd(3)+1:CMND.CmndEnd(3)+41)
        end if

      else if ( i .eq. 11 ) then ! XaxisTItle
        if ( (CMND.CmndText(4) .eq. '***') .or. (CMND.NumCmnd .eq. 3) ) then
          CHOPT.XaxisLabel= blank40
        else           
          CHOPT.XaxisLabel= CMND.Text(1)(CMND.CmndEnd(3)+1:CMND.CmndEnd(3)+41)
        end if

      else if ( i .eq. 12 ) then ! numberXDiVisions
        if ( (.not. CMND.CmndNumOK(4)) .or.
     &       (CMND.CmndIntVal(4) .lt. 1) .or.
     &       (CMND.CmndIntVal(4) .gt. 20)     ) goto 1080 ! error
        CHOPT.NumXDiv= CMND.CmndIntVal(4)

      else if ( i .eq. 13 ) then ! FONt number
        if ( (.not. CMND.CmndNumOK(4)) .or.
     &       (CMND.CmndIntVal(4) .lt. 1) .or.
     &       (CMND.CmndIntVal(4) .gt. 30)     ) goto 1090 ! error
        CHOPT.Font= CMND.CmndIntVal(4)
 
      end if             
      return

1000  write(6,1005)
1005  format(' Error- There must be at least 4 entries in the option command')
      return

1010  write(6,1015) CMND.CmndText(3),(ChOptType(i),i=1,11)
1015  format(' Error- ',a3,' is not a valid stripchart option'/
     &       '        Valid options are: RESet '/
     &       2(27x,7(a3,1x)/) )            
      return

1020  write(6,1025)
1025  format(' Error- The EVEnt option requires an on/off flag'/
     &       '        OPT SCH EVE ON/OFF')
      return

1030  write(6,1035)
1035  format(' Error- The chart LABel option requires an on/off flag'/
     &       '        OPT SCH LAB ON/OFF')
      return

1040  write(6,1045)
1045  format(' Error- The MaNual X option requires an on/off flag or xmin & xmax'/
     &       '        OPT SCH MNX ON/OFF  or  OPT SCH MNX 0 100')
      return

1050  write(6,1055) CMND.CmndText(4)
1055  format(' Error- X minimum ',a3,' in OPT SCH MNX is not a valid number')
      return

1060  write(6,1065) CMND.CmndText(5)
1065  format(' Error- X maximum ',a3,' in OPT SCH MNX is not a valid number')
      return

1070  write(6,1075) 
1075  format(' Error- The SCReen option requires an on/off flag'/
     &       '        OPT SCH SCR ON/OFF')
      return

1080  write(6,1085) CMND.CmndText(4)
1085  format(' Error- ',a3,' is not a valid number of x axis divisions'/
     &       '        Valid divisions are from 1 to 20 ')
      return             

1090  write(6,1095) CMND.CmndText(4)
1095  format(' Error- ',a3,' is not a valid font number'/
     &       '        Valid fonts are from 1 to 30 ')
      return

1100  write(6,1105) 
1105  format(' Error- The PRInt option requires an on/off flag'/
     &       '        OPT SCH PRI ON/OFF')
      return

1110  write(6,1115) 
1115  format(' Error- The SimpleAutoScale option requires an on/off flag'/
     &       '        OPT SCH SAS ON/OFF')
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      subroutine swapr( num1,num2 )
      implicit none

      real*4 num1,num2,temp

      temp= num1
      num1= num2
      num2= temp
      return
      end
c                       
c   Copyright (c) 1990 by Dwight Meglan                                       
c                                   
      subroutine ResetSChartOpt
      implicit none

      include 'tel_cons.inc'   
      include 'tel_strc.inc'
      include 'tel_chrt.inc'

      integer*4 i

      CHOPT.EventOn=      .true.
      CHOPT.DisplayTitle= .true.
      CHOPT.DisplayLabel= .true.
      CHOPT.ManLabel=     .false.
      CHOPT.ManXaxis=     .false.
      CHOPT.SimpleAutoScale= .false.
      CHOPT.Print=        .false.
      CHOPT.Screen=       .true.
      CHOPT.UsePostPrint= .false.
      do i= 1, 40
         CHOPT.Title(i:i)= ' '
         CHOPT.Subtitle(i:i)= ' '
         CHOPT.XaxisLabel(i:i)= ' '
         CHOPT.ChartLabel(i:i)= ' '
      end do
      CHOPT.Title(1:13)=        'Title not set'
      CHOPT.SubTitle(1:16)=     'SubTitle not set'
      CHOPT.ChartLabel(1:14)=   'No Chart Label'
      CHOPT.XaxisLabel(1:12)=   'X Axis Label'
      CHOPT.NumXDiv=      5
      CHOPT.Font=         1
      CHOPT.Xmin=         0.0
      CHOPT.Xmax=         100.0
      return                    
      end                        
                          
