cSUBROUTNIE PLOTSTYLE *******************************************************************
	subroutine sfspltstyle(dev,gopt,opt,mxvar,red,green,blue,pen,colline,
     *       coltext,colbox,mnxtic,mnytic,mnztic,symbol,colsym,
     *       mxxtic,mxytic,mxztic,xhigh,xlow,yhigh,ylow,zhigh,zlow,bg)             
c
c	sets up variables for passing to plplot routines that govern color and 
c	line style changes to plots and all sorts of bells and whistles -pjk
c
	integer*4 gopt,opt,mxvar
	integer*4 red,green,blue,pen(mxvar),colline(mxvar),coltext,colbox
	integer*4 mnxtic,mnytic,mnztic,symbol(mxvar),colsym(mxvar)
	real*4 mxxtic,mxytic,mxztic,xhigh,xlow,yhigh,ylow,zhigh,zlow
       character*8 dev
       logical bg
c local
	integer*4 tmp
c
c Begin subroutine
	if((gopt.gt.1.and.gopt.le.5).or.(gopt.eq.21))then
	  write(*,'(/13x,''color table ______________________________________________'')')
	  write(*,'(13x,''white(0) red(1)  yellow(2)  green(3)  aquamarine(4) pink(5) '')')
	  write(*,'(13x,''wheat(6)  grey(7)  browm(8)  blue(9)  blueviolet(10)'')')
	  write(*,'(13x,''cyan(11)  turquoise(12)  magenta(13)  salmon(14)  black(15)'')')
	  write(*,'(13x,''___________________________________________________________'',/)')
	else if(gopt.eq.1)then
	  write(*,'(/13x,''color table (background only) ____________________________'')')
	  write(*,'(13x,''black(0) white(1)  user defined (2)'')')
	  write(*,'(13x,''___________________________________________________________'',/)')
	endif  
	select case (gopt)
	   case(1)
	      write(*,'(/13x,''select new background color [0/1/2] : '',$)')
	      read(*,*)tmp
	      if(tmp.eq.0)then
	        red=0
	        blue=0
	        green=0
	        bg=.true.
	      elseif(tmp.eq.1)then
	        red=255
	        green=255
	        blue=255
	        bg=.false.
	      elseif(tmp.eq.2)then
	        write(*,'(13x,''enter red value [0-255] > '',$)')
	        read(*,*)red
	        write(*,'(13x,''enter green value [0-255] > '',$)')
	        read(*,*)green
	        write(*,'(13x,''enter blue value [0-255] > '',$)')
	        read(*,*)blue
	        bg=.false.
	      endif
c	      close(winu2)
	      return
	   case(2)
	      write(*,'(13x,''select new frame color [0-15] : '',$)')
	      read(*,*)colbox
c	      close(winu2)
	      return
	   case(3)
	      write(*,'(/13x,''select new text color: [0-15] : '',$)')
	      read(*,*)coltext
c	      close(winu2)
	      return
	   case(4)
	      write(*,'(13x,''select new line color: [0-15] : '',$)')
	      read(*,'(i4)')colline(1)
c	      close(winu2)
	      return
	   case(5)
	      write(*,'(13x,''select new curve color: [0-15] : '',$)')
	      read(*,'(i4)')colline(2)
c	      close(winu2)
	      return
	   case(6)
	      write(*,'(/13x,''select new line style: [0-8] : '',$)')
	      read(*,'(i4)')pen(1)
c	      close(winu2)
	      return
	   case(7)
	      write(*,'(/13x,''select new curve width: [0-8]  : '',$)')
	      read(*,'(i4)')pen(2)
c	      close(winu2)
	      return
	   case(8)
	      write(*,'(/13x,''change x axis major tics from: '',f6.0)')mxxtic
	      write(*,'(13x,''to > '',$)')
	      read(*,*)mxxtic
c	      close(winu2)
	      return
	   case(9)
	      write(*,'(/13x,''change x axis minor tics from: '',i4)')mnxtic
	      write(*,'(13x,''to > '',$)')
	      read(*,*)mnxtic
c	      close(winu2)
	      return
	   case(10)
	      write(*,'(/13x,''change y axis major tics from: '',f6.0)')mxytic
	      write(*,'(13x,''to > '',$)')
	      read(*,*)mxytic
c	      close(winu2)
	      return
	   case(11)
	      write(*,'(/13x,''change y axis minor tics from: '',i4)')mnytic
	      write(*,'(13x,''to > '',$)')
	      read(*,'(i4)')mnytic
c	      close(winu2)
	      return
	   case(12)
	      write(*,'(/13x,''change z axis major tics from: '',f6.0)')mxztic
	      write(*,'(13x,''to > '',$)')
	      read(*,*)mxztic
c	      close(winu2)
	      return
	   case(13)
	      write(*,'(/13x,''change z axis minor tics from: '',i4)')mnztic
	      write(*,'(13x,''to > '',$)')
	      read(*,'(i4)')mnztic
c	      close(winu2)
	      return
	   case(14)
	      write(*,'(/13x,''change x axis max value from: '',f8.3)')xhigh
	      write(*,'(13x,''to > '',$)')
	      read(*,*)xhigh
c	      close(winu2)
	      return
	   case(15)
	      write(*,'(/13x,''change x axis min value from: '',f8.3)')xlow
	      write(*,'(13x,''to > '',$)')
	      read(*,*)xlow
c	      close(winu2)
	      return
	   case(16)
	      write(*,'(/13x,''change y axis max value from: '',f8.3)')yhigh
	      write(*,'(13x,''to > '',$)')
	      read(*,*)yhigh
c	      close(winu2)
	      return
	   case(17)
	      write(*,'(/13x,''change y axis min value from: '',f8.3)')ylow
	      write(*,'(13x,''to > '',$)')
	      read(*,*)ylow
c	      close(winu2)
	      return
	   case(18)
	      write(*,'(/13x,''change z axis max value from: '',f8.3)')zhigh
	      write(*,'(13x,''to > '',$)')
	      read(*,*)zhigh
c	      close(winu2)
	      return
	   case(19)
	      write(*,'(/13x,''change z axis min value from: '',f8.3)')zlow
	      write(*,'(13x,''to > '',$)')
	      read(*,*)zlow
c	      close(winu2)
	      return
	   case(20)
	      write(*,'(/13x,''change symbol [0-126, 32 = no symbol]: '',i4)')symbol(1)
	      write(*,'(13x,''to > '',$)')
	      read(*,*)symbol(1)
c	      close(winu2)
	      return
	   case(21)
	      write(*,'(/13x,''change symbol color from: '',i4)')colsym(1)
	      write(*,'(13x,''to > '',$)')
	      read(*,*)colsym(1)
c	      close(winu2)
	      return
	   case(99)     !reset all options
	      red=255; blue=255; green=255
	      coltext=15; colbox=15
	      pen(1)=1; pen(2)=2
	      colsym(1)=9; symbol(1)=20
	      colline(1)=15; colline(2)=1; colline(3)=9
	      dev='xwin'; bg=.false.
	      xlow=99999.;  xhigh=-99999.;ylow=99999.
	      yhigh=-99999.;zlow=99999.;  zhigh=-99999.
	      return
	end select  
	
100	return
	end
c************************************************************************
c MODIFIED 12/06 to use routine scale for extra large x,y,z spans -PJK
c Modified 01/18 to scale Sectrum X axis properly. -pjk
c
	subroutine ticit(xlow,xhigh,ylow,yhigh,zlow,zhigh,mnxtic,mnytic,mnztic,
     *                    mxxtic,mxytic,mxztic)
c
c Argument declarations
	integer mnxtic,mnytic,mnztic
	real*4 xlow,xhigh,ylow,yhigh,zlow,zhigh,mxxtic,mxytic,mxztic
c Local
	integer ifault
	real*4 yt1,thigh,tlow,span
c
c Begin subroutine to define the major and minor tic mark intervals for plotting
c
	span=abs(xhigh-xlow)
c
c  set major and minor ticks depending on x, y and z range (span)
c xaxis scales
	if(span.le.0.1)then
	  mxxtic=.02
	  mnxtic=5
	elseif(span.gt.0.1.and.span.le.1.0)then
	  mxxtic=.1
	  mnxtic=10
	elseif(span.gt.1.0.and.span.le.25)then
	  mxxtic=5
	  mnxtic=51
	elseif(span.gt.25.and.span.le.50)then
	  mxxtic=10.0
	  mnxtic=10
	elseif(span.gt.50.and.span.le.100)then
	  mxxtic=20
	  mnxtic=5
	elseif((span.le.200.0).and.(span.gt.100))then
	  mxxtic=20.0
	  mnxtic=10
	else if(span.le.500.0.and.span.gt.200.0)then
 	  mxxtic=50.0
	  mnxtic=5
	else if(span.le.1000.0.and.span.gt.500.0)then
	  mxxtic=100.0
	  mnxtic=10
	else if(span.le.2000.0.and.span.gt.1000)then
	  mxxtic=250.0
	  mnxtic=5
	elseif(span.gt.2000)then
c determine optimum x scale axis parameters
	  call SCALE(xlow, xhigh, 10, tlow, mxxtic, thigh, IFAULT)
	  xlow=tlow;xhigh=thigh
	  mnxtic=5
	end if
c yaxis scales
c 	round yhigh up or down depending on scale
	if(yhigh.lt.10)then
	   yt1=amod(yhigh,1.0)
	   if(yt1.le.0.5)then
	    yhigh=yhigh+(0.5-yt1)	
	   else
	    yhigh=yhigh+((1.0-yt1))
	   endif	
	elseif((yhigh.ge.10).and.(yhigh.lt.100))then
	   yt1=amod(yhigh,10.0)
	   if(yt1.le.5.0)then
	     yhigh=yhigh+(5.0-yt1)	
	   else
	     yhigh=yhigh+((10.0-yt1))
	   endif
	elseif(yhigh.ge.100)then
	   yt1=amod(yhigh,100.0)
	   if(yt1.le.50.0)then
	     yhigh=yhigh+(50.0-yt1)	
	   else
	     yhigh=yhigh+((100.0-yt1))
	   endif
	endif
c
	if(ylow.ge.0)then
	   span=yhigh-ylow
	else
	   span=yhigh+abs(ylow)
	endif
c
	if(span.le.2.0)then
	  mxytic=0.5
	  mnytic=4
	else if(span.gt.2.0.and.span.le.4.0)then
	  mxytic=1.0
	  mnytic=4
	else if(span.gt.4.0.and.span.le.10.0)then
	  mxytic=2.0
	  mnytic=4
	else if(span.gt.10.0.and.span.le.50.0)then
	  mxytic=5.0
	  mnytic=5
	else if(span.gt.50.and.span.le.100.0)then
	  mxytic=10.0
	  mnytic=2
	else if(span.gt.100.and.span.le.500)then
	  mxytic=100.0
	  mnytic=5
	else if(span.gt.500)then
c determine optimum x scale axis parameters
	  call SCALE(ylow, yhigh, 10, tlow, mxytic, thigh, IFAULT)
	  ylow=tlow;yhigh=thigh
	  mnxtic=5
	end if
c
c zaxis scales
c 	round zhigh up or down depending on scale
	if(zhigh.lt.10)then
	   yt1=amod(zhigh,1.0)
	   if(yt1.le.0.5)then
	    zhigh=zhigh+(0.5-yt1)	
	   else
	    zhigh=zhigh+((1.0-yt1))
	   endif	
	elseif((zhigh.ge.10).and.(zhigh.lt.100))then
	   yt1=amod(zhigh,10.0)
	   if(yt1.le.5.0)then
	     zhigh=zhigh+(5.0-yt1)	
	   else
	     zhigh=zhigh+((10.0-yt1))
	   endif
	elseif(zhigh.ge.100)then
	   yt1=amod(zhigh,100.0)
	   if(yt1.le.50.0)then
	     zhigh=zhigh+(50.0-yt1)	
	   else
	     zhigh=zhigh+((100.0-yt1))
	   endif
	endif
c
	if(zlow.ge.0)then
	   span=zhigh-zlow
	else
	   span=zhigh+abs(zlow)
	endif
c
	if(span.le.2.0)then
	  mxztic=0.5
	  mnztic=4
	else if(span.gt.2.0.and.span.le.4.0)then
	  mxztic=1.0
	  mnztic=4
	else if(span.gt.4.0.and.span.le.10.0)then
	  mxztic=2.0
	  mnztic=4
	else if(span.gt.10.0.and.span.le.50.0)then
	  mxztic=5
	  mnztic=5
	else if(span.gt.50.and.span.le.100.0)then
	  mxztic=10.0
	  mnztic=2
	else if(span.gt.100.and.span.le.500)then
	  mxztic=100.0
	  mnztic=5
	else if(span.gt.500)then
c determine optimum x scale axis parameters
	  call SCALE(zlow, zhigh, 10, tlow, mxztic, thigh, IFAULT)
	  zlow=tlow;zhigh=thigh
	  mnztic=5
	end if
	return
	end
c***********************************************************************
      SUBROUTINE SCALE(FMN, FMX, N, VALMIN, STEP, VALMAX, IFAULT)
C
C     ALGORITHM AS 96  APPL. STATIST. (1976) VOL.25, NO.1
C
C     Given extreme values FMN, FMX, and the need for a scale with N
C     marks, calculates value for the lowest scale mark (VALMIN) and
C     step length (STEP) and highest scale mark (VALMAX).
C
      REAL FMN, FMX, VALMIN, STEP, VALMAX
      INTEGER N, IFAULT
C
C     Units for step lengths
C
      REAL UNIT(11)
C
C     Local variables
C
      INTEGER NUNIT, I, J
      REAL TOL, ZERO, HALF, ONE, TEN, BIAS, FMAX, FMIN, RN, X, S, RANGE
C
C     Array length unit()
C
      DATA NUNIT /11/
C
C     Local constant, defining effective equality of values.
C
      DATA TOL /5.0E-6/
      DATA ZERO /0.0/, HALF /0.5/, ONE /1.0/, TEN /10.0/
      DATA BIAS /1.0E-4/
      DATA UNIT /1.0, 1.2, 1.6, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 8.0,
     *        10.0/
C
      FMAX = FMX
      FMIN = FMN
      IFAULT = 1
C
C     Test for valid parameter values
C
      IF (FMAX .LT. FMIN .OR. N .LE. 1) RETURN
      IFAULT = 0
      RN = N - 1
      X = ABS(FMAX)
      IF (X .EQ. ZERO) X = ONE
      IF ((FMAX - FMIN) / X .GT. TOL) GO TO 20
C
C     All values effectively equal
C
      IF (FMAX .LT. ZERO) THEN
        FMAX = ZERO
      ELSE IF (FMAX .EQ. ZERO) THEN
        FMAX = ONE
      ELSE
        FMIN = ZERO
      END IF
C
   20 STEP = (FMAX - FMIN) / RN
      S = STEP
C
C     Find power of 10
C
   25 IF (S .GE. ONE) GO TO 30
      S = S * TEN
      GO TO 25
   30 IF (S .LT. TEN) GO TO 35
      S = S / TEN
      GO TO 30
C
C     Calculate STEP
C
   35 X = S - BIAS
      DO 40 I = 1, NUNIT
        IF (X .LE. UNIT(I)) GO TO 45
   40 CONTINUE
   45 STEP = STEP * UNIT(I) / S
      RANGE = STEP * RN
C
C     Make first estimate of VALMIN
C
      X = HALF * (ONE + (FMIN + FMAX - RANGE) / STEP)
      J = X - BIAS
      IF (X .LT. ZERO) J = J - 1
      VALMIN = STEP * FLOAT(J)
C
C     Test if VALMIN could be zero
C
      IF (FMIN .GE. ZERO .AND. RANGE .GE. FMAX) VALMIN = ZERO
      VALMAX = VALMIN + RANGE
C
C     Test if VALMAX could be zero
C
      IF (FMAX .GT. ZERO .OR. RANGE .LT. -FMIN) RETURN
      VALMAX = ZERO
      VALMIN = -RANGE
      RETURN
      END
c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
