ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
*sbr plot1
*
      subroutine plot1(nmax,wrk,sp,ny,iy,xlab,ylab,tit,rline,annot1,annot2,iw1,iw2,iw3)
c
c     argument
      integer nmax,ny,iy,iw1,iw2,iw3
      dimension sp(nmax),wrk(nmax),rline(nmax)
      character tit*60,xlab*20,ylab*20,annot1*36,annot2*36
c     local
      integer p
      real*4 x(6000),thigh	      
      character filename*70,ans*2
c
c PlotStyle variables
	integer*4 gopt,opt,mxvar
	parameter (mxvar=20)
	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
1	gopt=99
       call 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
       ylow=100000.0;   yhigh=-100000.0
c
 	do p=1,ny
         if(wrk(p).gt.yhigh)yhigh=wrk(p)
         if(sp(p).gt.yhigh)yhigh=sp(p)
         if(wrk(p).lt.ylow)ylow=wrk(p)
         if(sp(p).lt.ylow)ylow=sp(p)
         x(p)=iy+p-1
	enddo
	if(rline(1).eq.0.85)yhigh=1.0
	irange=yhigh-ylow
	yhigh=yhigh+irange/10
	ylow=ylow-irange/10
c      
	xlow=iy;xhigh=iy+ny-1
c
	call scale(xlow, xhigh, 10, tlow, mxxtic, thigh, ifault)
	xlow=tlow;xhigh=thigh
	mnxtic=5
c
	if(iw3.eq.0)ylow=0.
c      
	call scale(ylow, yhigh, 10, tlow, mxytic, thigh, ifault)
	ylow=tlow;yhigh=thigh
	mnytic=5
c
	call plsdev('xwin')
	call plsetopt('geometry','1000x600')          !set default plot window dimension
	colline(1)=1;colline(2)=9
c
10	continue
c
c set background color
c
	if(.not.bg)then
        call plscol0(0,255,255,255)              !change default color map black>white 
        call plscol0(15,0,0,0)                   !change default color map white>black
        call plscolbg(red,green,blue)            !change background color if other than white is desired
	elseif(bg)then
        call plscol0(15,255,255,255)              !change default color map white>black
        call plscol0(0,0,0,0)                   !change default color map black>white
        call plscolbg(red,green,blue)            !change background color if other than white is desired
	endif  
c
c     initialize plplot
	call plinit()
c     define the viewport one column by one rows
	call plssub(1,1)
c     set lable color
	call plcol0(15)   !color box and lables
	
	call pladv(0) 
	call plvpor(0.125,0.92,0.15,0.85)  !top plot window
	call plwind(xlow,xhigh,ylow,yhigh)
	call plaxes (xlow,ylow,'abitnr',mxxtic,mnxtic,'abinstv',mxytic,mnytic)
	
cc    call plenv(mnx,mx,mny,mxy,0,0)
	if(rline(1).ne.-999.9)then
c     set curve width
	call plwid(iw3)
	if(rline(1).eq.0.85)call pllsty(pen(1))
          call plline(ny,x,rline)            !plot rline
	endif
c
	call plfont(1)      
	call plwid(1)
	call pllab(xlab,ylab,' ')
       call plmtex('b',-30.,.5,0.5,tit)
      
c     set line style
      call pllsty(1)
      call plcol0(colline(1))  !color lines
      call plwid(pen(1))
      call plline(ny,x,wrk)            !plot wrk
      call plwid(1)
      if(annot1(1:5).ne.'     ')call plmtex('b',-28.,0.06,0.0,annot1)
      call plcol0(colline(2))  !color lines
      call plwid(pen(2))
      call plline(ny,x,sp)           !plot spline curve
      call plwid(1)
      if(annot2(1:5).ne.'     ')call plmtex('b',-28.,0.55,0.0,annot2)
c     
      call plend()
c  
       ans='C ';dev='xwin'
51	write(*,'(//15x,''|************* plot options menu **************|'')')
       write(*,'(15x,''| replot             [0]  minor ticks y   [11] |'')')
	write(*,'(15x,''| background color   [1]  major ticks z    [-] |'')')
 	write(*,'(15x,''| frame color        [-]  minor ticks z    [-] |'')')
	write(*,'(15x,''| text color         [-]  max. x          [14] |'')')
	write(*,'(15x,''| line color         [4]  min. x          [15] |'')')
       write(*,'(15x,''| curve  color       [5]  max. y          [16] |'')')
       write(*,'(15x,''| line  width        [6]  min. y          [17] |'')')
       write(*,'(15x,''| curve width        [7]  max. z           [-] |'')')
       write(*,'(15x,''| major ticks x      [8]  min. z           [-] |'')')
       write(*,'(15x,''| minor ticks x      [9]  symbol type      [-] |'')')
       write(*,'(15x,''| major ticks y     [10]  symbol color     [-] |'')')
	write(*,'(15x,''|                                              |'')')
	write(*,'(15x,''|              reset options  [99]             |'')')
	write(*,'(15x,''|----------------------------------------------|'')')
       write(*,'(15x,''|    [s]ave   <[c]ontinue>  [n]o more plots    |'')') 
       write(*,'(15x,''|______________________________________________|'')')
	write(*,'(/15x,'' enter option number > '',$)')
      read(*,'(a2)',err=51)ans
      if((ans.eq.'S ').or.(ans.eq.'s '))then
         write(*,'(/15x,''NOTE: The image file you are about to create is PostScript. '')')
         write(*,'(15x,''To make this readily apparent to your OS we recommend adding'')')
         write(*,'(15x,''the extension .ps to the file name.'')')
         call blank(filename)
         write(*,'(15x,''Enter plot file name > '',$)')
         read(*,'(a70)',err=991)filename   
         call lalign(filename)
	  call plsetopt('geometry','600x800')          !change default plot window dimension for printing only
	  call plsdev('psc')	  
         call plsfnam(filename)
         goto 10
      elseif((ans.eq.'C ').or.(ans.eq.'c ').or.(ans.eq.'  ').or.
     *                             (ans.eq.'Y ').or.(ans.eq.'y '))then
         return
      elseif((ans.eq.'N ').or.(ans.eq.'n '))then
         return
      else
         read(ans(1:2),'(i2)',err=51)gopt     !convert ans to gopt then continue
      endif
      if((gopt.gt.0).and.(gopt.le.21))then
         call 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)                         
         goto 51  !50
      else if(gopt.eq.0)then
          dev='xwin'   !set plot output device back to screen
	   call plsetopt('geometry','1000x600')          !set default plot window dimension
	   call plsdev(dev) 
          goto 10    !replot
      elseif(gopt.eq.22)then
	   write(*,'(/15x,''change z2 axis max value from: '',f8.3)')bhigh
	   write(*,'(13x,''to > '',$)')
	   read(*,*)bhigh
	   goto 51
      elseif(gopt.eq.23)then
	   write(*,'(/15x,''change z2 axis min. value from: '',f8.3)')blow
	   write(*,'(13x,''to > '',$)')
	   read(*,*)blow
	   goto 51
      else if(gopt.eq.99)then
         goto 1
      else
        write(*,'(/13x,''unknown option re-enter a valid request'')')
        goto 51
      end if
c
	return
c
991	write(*,'(/15x,''Error reading plot file name'')')
	write(*,'(15x,''Try again and do not forget to append'')')
	write(*,'(15x,''the extension .ps'')')
	goto 51
c
	end
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
	subroutine plt1(mxsl,rmax,mey,ycal,fycaly,lycaly,flag,string,mnpoff)
c
c	argument
	integer mxsl,rmax,mnpoff
	integer fycaly,lycaly
	real*4 mey(mxsl),ycal(mxsl)
	character string*30
c	local
	integer p,k
	real*4 wrk1(6000),wrk2(6000),wrk3(6000)
	character ans*2,filename*70
c
c PlotStyle variables
	integer*4 gopt,opt,mxvar
	parameter (mxvar=20)
	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
1	gopt=99
       call 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
	xlow=real(0); xhigh=real(lycaly+mnpoff)	
	ylow=9999.;yhigh=-9999.;p=1
	do k=fycaly,lycaly
	    if(mey(k).ne.flag.and.mey(k).gt.yhigh)yhigh=mey(k)
	    if(mey(k).ne.flag.and.mey(k).lt.ylow)ylow=mey(k)
	    if(ycal(k).ne.flag.and.ycal(k).lt.ylow)ylow=ycal(k)
	    if(ycal(k).ne.flag.and.ycal(k).gt.yhigh)yhigh=ycal(k)
	    wrk1(k)=real(k+mnpoff)   !x axis data 
	    wrk2(k)=ycal(k+mnpoff)   !rc
	    wrk3(k)=mey(k+mnpoff)    !input series
	    if(wrk2(k).ne.flag)p=p+1
	enddo
	p=p-1
c
	call  ticit(xlow,xhigh,ylow,yhigh,zlow,zhigh,mnxtic,mnytic,mnztic,
     *                    mxxtic,mxytic,mxztic)
c      
	call plsdev(dev)
	call plsetopt('geometry','1000x600')          !set default plot window dimension
c	
10	continue
c
c set background color
c
	if(.not.bg)then
        call plscol0(0,255,255,255)              !change default color map black>white 
        call plscol0(15,0,0,0)                   !change default color map white>black
        call plscolbg(red,green,blue)            !change background color if other than white is desired
	elseif(bg)then
        call plscol0(15,255,255,255)              !change default color map white>black
        call plscol0(0,0,0,0)                   !change default color map black>white
        call plscolbg(red,green,blue)            !change background color if other than white is desired
	endif  
c
c initialize plplot
	call plinit()
c set lable color
	call plcol0(15)   !color box and lables
c define the viewport one column by one rows
	call plssub(1,1)
       call plwid(1)
	call pladv(0) 
	call plvpor(0.125,0.92,0.15,0.85)  !top plot window
	call plwind(xlow,xhigh,ylow,yhigh)
	call plaxes (xlow,ylow,'abitnr',mxxtic,mnxtic,'abinstv',mxytic,mnytic)
	call pllab('Biological Year','Y',string)
	call plcol0(colline(1))   !color box and lables
	call plline(p,wrk1,wrk3)
	call plcol0(colline(2))   !color box and lables
	call plwid(2)
	call plline(p,wrk1,wrk2)
	call plend()
c	
       ans='C '
51	write(*,'(//15x,''|************* plot options menu **************|'')')
       write(*,'(15x,''| replot             [0]  minor ticks y   [11] |'')')
	write(*,'(15x,''| background color   [1]  major ticks z    [-] |'')')
 	write(*,'(15x,''| frame color        [-]  minor ticks z    [-] |'')')
	write(*,'(15x,''| text color         [-]  max. x          [14] |'')')
	write(*,'(15x,''| line color         [4]  min. x          [15] |'')')
       write(*,'(15x,''| curve  color       [5]  max. y          [16] |'')')
       write(*,'(15x,''| line style         [-]  min. y          [17] |'')')
       write(*,'(15x,''| curve width        [-]  max. z           [-] |'')')
       write(*,'(15x,''| major ticks x      [8]  min. z           [-] |'')')
       write(*,'(15x,''| minor ticks x      [9]  symbol type      [-] |'')')
       write(*,'(15x,''| major ticks y     [10]  symbol color     [-] |'')')
	write(*,'(15x,''|                                              |'')')
	write(*,'(15x,''|              reset options  [99]             |'')')
	write(*,'(15x,''|----------------------------------------------|'')')
       write(*,'(15x,''|    [s]ave   <[c]ontinue>  [n]o more plots    |'')') 
       write(*,'(15x,''|______________________________________________|'')')
	write(*,'(/15x,'' enter option number > '',$)')
      read(*,'(a2)',err=51)ans
      if((ans.eq.'S ').or.(ans.eq.'s '))then
         write(*,'(/15x,''NOTE: The image file you are about to create is PostScript. '')')
         write(*,'(15x,''To make this readily apparent to your OS we recommend adding'')')
         write(*,'(15x,''the extension .ps to the file name.'')')
         call blank(filename)
         write(*,'(15x,''Enter plot file name > '',$)')
         read(*,'(a70)',err=991)filename   
         call lalign(filename)
	  call plsetopt('geometry','600x800')          !change default plot window dimension for printing only
	  call plsdev('psc')	  
         call plsfnam(filename)
          goto 10
      elseif((ans.eq.'C ').or.(ans.eq.'c ').or.(ans.eq.'  ').or.
     *                             (ans.eq.'Y ').or.(ans.eq.'y '))then
         return
      elseif((ans.eq.'N ').or.(ans.eq.'n '))then
         return
      else
         read(ans(1:2),'(i2)',err=51)gopt     !convert ans to gopt then continue
      endif
      if((gopt.gt.0).and.(gopt.le.21))then
         call 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)                         
         goto 51  !50
      else if(gopt.eq.0)then
          dev='xwin'   !set plot output device back to screen
	   call plsetopt('geometry','1000x600')          !set default plot window dimension
	   call plsdev(dev) 
          goto 10    !replot
      elseif(gopt.eq.22)then
	   write(*,'(/15x,''change z2 axis max value from: '',f8.3)')bhigh
	   write(*,'(13x,''to > '',$)')
	   read(*,*)bhigh
	   goto 51
      elseif(gopt.eq.23)then
	   write(*,'(/15x,''change z2 axis min. value from: '',f8.3)')blow
	   write(*,'(13x,''to > '',$)')
	   read(*,*)blow
	   goto 51
      else if(gopt.eq.99)then
         goto 1
      else
        write(*,'(/13x,''unknown option re-enter a valid request'')')
        goto 51
      end if
c
	return
c
991	write(*,'(/15x,''Error reading plot file name'')')
	write(*,'(15x,''Try again and do not forget to append'')')
	write(*,'(15x,''the extension .ps'')')
	goto 51
c
	end
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
	subroutine plt2(mxy,mxs,pltdata,nc,idate,flag,string)
c
c	argument
	integer mxy,mxs,nc
	integer idate(mxs,3)
	real*4 pltdata(mxy,mxs),flag
	character string*30
c	local
	integer p,j,k,ny
	real*4 txlow,txhigh
	real*4 wrk1(6000),wrk2(6000),wrk3(6000),wrk4(6000)
	character ans*2,filename*70
c
c PlotStyle variables
	integer*4 gopt,opt,mxvar
	parameter (mxvar=20)
	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
1	gopt=99
       call 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
	call plsetopt('geometry','1000x600')          !set default plot window dimension
	call plsdev(dev)
c	
	do p=1,nc
	  j=1
	  do k=idate(p,1),idate(p,2)
	      if(pltdata(j,p).ne.flag.and.pltdata(j,p).gt.yhigh)yhigh=pltdata(j,p)
	      if(pltdata(j,p).ne.flag.and.pltdata(j,p).lt.ylow)ylow=pltdata(j,p)
	      j=j+1
	  enddo
	  if(idate(p,1).lt.xlow)xlow=idate(p,1)
	  if(idate(p,2).gt.xhigh)xhigh=idate(p,2)
	enddo
	txlow=xlow;txhigh=xhigh
c
	call  ticit(xlow,xhigh,ylow,yhigh,zlow,zhigh,mnxtic,mnytic,mnztic,
     *                    mxxtic,mxytic,mxztic)
c      
10	continue
c
c set background color
c
      if(.not.bg)then
        call plscol0(0,255,255,255)              !change default color map black>white 
        call plscol0(15,0,0,0)                   !change default color map white>black
        call plscolbg(red,green,blue)            !change background color if other than white is desired
      elseif(bg)then
        call plscol0(15,255,255,255)              !change default color map white>black
        call plscol0(0,0,0,0)                   !change default color map black>white
        call plscolbg(red,green,blue)            !change background color if other than white is desired
      endif  

c initialize plplot
	call plinit()
c set lable color
	call plcol0(15)   !color box and lables
c define the viewport one column by one rows
	call plssub(1,2)
	call pladv(0) 
       call plwid(1)
	call plvpor(0.125,0.92,0.15,0.85)  !top plot window
	call plwind(xlow,xhigh,ylow,yhigh)
	call plaxes (xlow,ylow,'abitnr',mxxtic,mnxtic,'abinstv',mxytic,mnytic)
	call pllab('Calendar Year','Y','First Detrending')	
	call plcol0(colline(1))   !color box and lables	
	do p=1,nc
	   k=1
	   do j=idate(p,1),idate(p,2)
	     wrk1(k)=real(j);wrk2(k)=pltdata(k,p)
	     k=k+1
	   enddo
	   k=k-1
	    call plline(k,wrk1,wrk2)     !draw individual indices
	enddo
c
c set lable color
	call pladv(0) 
	call plcol0(15)   !color box and lables
       call plwid(1)
	call plvpor(0.125,0.92,0.15,0.85)  !top plot window
	call plwind(xlow,xhigh,ylow,yhigh)
	call plaxes (xlow,ylow,'abitnr',mxxtic,mnxtic,'abinstv',mxytic,mnytic)
	call pllab('Calendar Year','Y','Average Indices')
	
	do p=1,mxy
	   wrk1(p)=0.;wrk2(p)=0.;wrk3(p)=0.
	enddo
	do p=1,nc
	   j=(idate(p,1)-txlow)+1
	   ny=(idate(p,2)-idate(p,1))+1
	   do k=1,ny
	     wrk2(j)=wrk2(j)+pltdata(k,p)
	     wrk3(j)=wrk3(j)+1.
	     j=j+1
	   enddo
	enddo	
	
	ny=txhigh-txlow+1; j=1	
	do k=1,ny
	   if(wrk3(k).ne.0)then
	       wrk1(k)=wrk2(k)/wrk3(k)
	       wrk4(k)=real(txlow+k-1)
	       j=j+1
	   endif
	enddo
	j=j-1
ccc	write(*,*)j,ny,txhigh,txlow
	call plcol0(colline(2))   !color box and lables	
	call plline(ny,wrk4,wrk1)       !draw average index
	call plcol0(15)   !color box and lables
	call plend()
c	
       ans='C '
51	write(*,'(//15x,''|************* plot options menu **************|'')')
       write(*,'(15x,''| replot             [0]  minor ticks y   [11] |'')')
	write(*,'(15x,''| background color   [1]  major ticks z    [-] |'')')
 	write(*,'(15x,''| frame color        [-]  minor ticks z    [-] |'')')
	write(*,'(15x,''| text color         [-]  max. x          [14] |'')')
	write(*,'(15x,''| line color(top)    [4]  min. x          [15] |'')')
       write(*,'(15x,''| line color(bottom) [5]  max. y          [16] |'')')
       write(*,'(15x,''| line style         [-]  min. y          [17] |'')')
       write(*,'(15x,''| curve width        [-]  max. z           [-] |'')')
       write(*,'(15x,''| major ticks x      [8]  min. z           [-] |'')')
       write(*,'(15x,''| minor ticks x      [9]  symbol type      [-] |'')')
       write(*,'(15x,''| major ticks y     [10]  symbol color     [-] |'')')
	write(*,'(15x,''|                                              |'')')
	write(*,'(15x,''|              reset options  [99]             |'')')
	write(*,'(15x,''|----------------------------------------------|'')')
       write(*,'(15x,''|    [s]ave   <[c]ontinue>  [n]o more plots    |'')') 
       write(*,'(15x,''|______________________________________________|'')')
	write(*,'(/15x,'' enter option number > '',$)')
       read(*,'(a2)',err=51)ans
       if((ans.eq.'S ').or.(ans.eq.'s '))then
         write(*,'(/15x,''NOTE: The image file you are about to create is PostScript. '')')
         write(*,'(15x,''To make this readily apparent to your OS we recommend adding'')')
         write(*,'(15x,''the extension .ps to the file name.'')')
         call blank(filename)
         write(*,'(15x,''Enter plot file name > '',$)')
         read(*,'(a70)',err=991)filename   
         call lalign(filename)
	  call plsetopt('geometry','600x800')          !change default plot window dimension for printing only
	  call plsdev('psc')	  
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'C ').or.(ans.eq.'c ').or.(ans.eq.'  ').or.
     *                             (ans.eq.'Y ').or.(ans.eq.'y '))then
         return
       elseif((ans.eq.'N ').or.(ans.eq.'n '))then
         return
       else
         read(ans(1:2),'(i2)',err=51)gopt     !convert ans to gopt then continue
       endif
       if((gopt.gt.0).and.(gopt.le.21))then
         call 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)                         
         goto 51  !50
       else if(gopt.eq.0)then
          dev='xwin'   !set plot output device back to screen
	   call plsetopt('geometry','1000x600')          !set default plot window dimension
	   call plsdev(dev) 
          goto 10    !replot
       elseif(gopt.eq.22)then
	   write(*,'(/15x,''change z2 axis max value from: '',f8.3)')bhigh
	   write(*,'(13x,''to > '',$)')
	   read(*,*)bhigh
	   goto 51
       elseif(gopt.eq.23)then
	   write(*,'(/15x,''change z2 axis min. value from: '',f8.3)')blow
	   write(*,'(13x,''to > '',$)')
	   read(*,*)blow
	   goto 51
       else if(gopt.eq.99)then
         goto 1
       else
        write(*,'(/13x,''unknown option re-enter a valid request'')')
        goto 51
       end if
c
	return
c
991	write(*,'(/15x,''Error reading plot file name'')')
	write(*,'(15x,''Try again and do not forget to append'')')
	write(*,'(15x,''the extension .ps'')')
	goto 51
c
	end
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
	subroutine plt3(mxy,mxs,indx,xrc,f,idate,flag,nmax,sernum,n,ident,string,plotall,pith,mnpoff)
c
c	argument
	integer mxy,mxs,nmax,sernum,n,mnpoff
	integer idate(mxs,3),pith(mxs)
	real*4 indx(mxy),flag,f(mxy),xrc(mxy)
	character ident(mxs)*8
	character string*30
	logical plotall
c	local
	integer p,j,k, mny2tic,mnx2tic
	real*4 x2low,x2high,y2low,y2high,mxx2tic,mxy2tic
	real*4 wrk1(6000),wrk2(6000),wrk3(6000),wrk4(6000)
	character ans*2,filename*70
c
c PlotStyle variables
	integer*4  gopt,opt,mxvar
	parameter  (mxvar=20)
	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
c
1	gopt=99
       call 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
	call plsetopt('geometry','1000x600')          !set default plot window dimension
	call plsdev(dev)
c
	k=1
	do p=1,nmax
	   if(xrc(p).ne.flag.and.xrc(p).gt.yhigh)yhigh=xrc(p)
	   if(f(p).ne.flag.and.f(p).gt.yhigh)yhigh=f(p)
	   wrk1(p)=real(p+pith(sernum))   !x axis series
	   wrk2(p)=real(p+mnpoff)         !xaxis rcf
	   wrk3(p)=f(p+mnpoff)
	   if(wrk3(p).ne.flag)k=k+1
	enddo
	k=k-1
c
	xlow=real(0); xhigh=real(nmax+mnpoff); ylow=0.0
c
	call  ticit(xlow,xhigh,ylow,yhigh,zlow,zhigh,mnxtic,mnytic,mnztic,
     *                    mxxtic,mxytic,mxztic)
c     
	x2high=real(idate(sernum,2)); x2low=real(idate(sernum,1))
	j=idate(sernum,1); y2low=0.; y2high=100.
	do p=1,n
	      if(indx(p).ne.flag.and.indx(p).gt.zhigh)zhigh=indx(p)
	      if(indx(p).ne.flag.and.indx(p).lt.zlow)zlow=indx(p)
	      wrk4(p)=real(j)
	      j=j+1
	enddo
c
	call  ticit(x2low,x2high,y2low,y2high,zlow,zhigh,mnx2tic,mny2tic,mnztic,
     *                    mxx2tic,mxy2tic,mxztic)
c     
10	continue
c
c set background color
c
      if(.not.bg)then
        call plscol0(0,255,255,255)              !change default color map black>white 
        call plscol0(15,0,0,0)                   !change default color map white>black
        call plscolbg(red,green,blue)            !change background color if other than white is desired
      elseif(bg)then
        call plscol0(15,255,255,255)              !change default color map white>black
        call plscol0(0,0,0,0)                   !change default color map black>white
        call plscolbg(red,green,blue)            !change background color if other than white is desired
      endif  
c	
c initialize plplot
	call plinit()
c set lable color
	call plcol0(15)   !color box and lables
c define the viewport one column by one rows
	call plssub(1,2)
       call plwid(1)
       
	call pladv(0) 
       call plwid(1)
	call plvpor(0.125,0.92,0.15,0.85)  !top plot window
	call plwind(xlow,xhigh,ylow,yhigh)
	call plaxes (xlow,ylow,'abitnr',mxxtic,mnxtic,'abinstv',mxytic,mnytic)
       
ccc	call plenv(real(0),real(nmax+mnpoff),0.,maxy,0,2)
	
	call pllab('Biological Year','Y',string)
	call plcol0(1)   !color box and lables
	call plline(n,wrk1,xrc)
	call plcol0(9)   !color box and lables
	call plwid(2)
	call plline(k,wrk2,wrk3)
c
c bottom plot
c
c set lable color
	call plcol0(15)   !color box and lables
       call plwid(1)
       
	call pladv(0) 
       call plwid(1)
	call plvpor(0.125,0.92,0.15,0.85)  !top plot window
	call plwind(x2low,x2high,zlow,zhigh)
	call plaxes (x2low,zlow,'abitnr',mxx2tic,mnx2tic,'abinstv',mxztic,mnztic)
             
ccc	call plenv(real(idate(sernum,1)),real(idate(sernum,2)),miny,maxy,0,2)

	call pllab('Calendar Year','Y',ident(sernum))
	call plcol0(1)   !color box and lables
	call plline(n,wrk4,indx)
c	
	call plend()
c		
       ans='C '
51	write(*,'(//15x,''|******************** plot options menu *******************|'')')
       write(*,'(15x,''| replot                 [0]  minor ticks y (top)     [11] |'')')
	write(*,'(15x,''| background color       [1]  major ticks z (y bottom)[12] |'')')
 	write(*,'(15x,''| frame color            [-]  minor ticks z (y bottom)[13] |'')')
	write(*,'(15x,''| text color             [-]  max. x (top)            [14] |'')')
	write(*,'(15x,''| line color (top)       [4]  min. x (top)            [15] |'')')
       write(*,'(15x,''| line color (bottom)    [5]  max. y (top)            [16] |'')')
       write(*,'(15x,''| line style             [-]  min. y (top)            [17] |'')')
       write(*,'(15x,''| curve width            [-]  max. z (Y bottom)       [18] |'')')
       write(*,'(15x,''| major ticks x(top)     [8]  min. z (Y bottom)       [19] |'')')
       write(*,'(15x,''| minor ticks x(top)     [9]  symbol type              [-] |'')')
       write(*,'(15x,''| major ticks y(top)     [10] symbol color             [-] |'')')
       write(*,'(15x,''| max. x (bottom)        [22] min. x (bottom)         [23] |'')')
       write(*,'(15x,''| major ticks x (bottom) [24] minor ticks x (bottom)  [25] |'')')
	write(*,'(15x,''|                                                          |'')')
	write(*,'(15x,''|                   reset options  [99]                    |'')')
	write(*,'(15x,''|----------------------------------------------------------|'')')
       write(*,'(15x,''|           [s]ave   <[c]ontinue>  [n]o more plots         |'')') 
       write(*,'(15x,''|__________________________________________________________|'')')
	write(*,'(/15x,'' enter option number > '',$)')
      read(*,'(a2)',err=51)ans
      if((ans.eq.'S ').or.(ans.eq.'s '))then
         write(*,'(/15x,''NOTE: The image file you are about to create is PostScript. '')')
         write(*,'(15x,''To make this readily apparent to your OS we recommend adding'')')
         write(*,'(15x,''the extension .ps to the file name.'')')
         call blank(filename)
         write(*,'(15x,''Enter plot file name > '',$)')
         read(*,'(a70)',err=991)filename   
         call lalign(filename)
	  call plsetopt('geometry','600x800')          !change default plot window dimension for printing only
	  call plsdev('psc')	  
         call plsfnam(filename)
         goto 10
      elseif((ans.eq.'C ').or.(ans.eq.'c ').or.(ans.eq.'  ').or.
     *                             (ans.eq.'Y ').or.(ans.eq.'y '))then
         return
      elseif((ans.eq.'N ').or.(ans.eq.'n '))then
         plotall=.false.
         return
      else
         read(ans(1:2),'(i2)',err=51)gopt     !convert ans to gopt then continue
      endif
      if((gopt.gt.0).and.(gopt.le.21))then
         call 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)                         
         goto 51  !50
      else if(gopt.eq.0)then
          dev='xwin'   !set plot output device back to screen
	   call plsetopt('geometry','1000x600')          !set default plot window dimension
	   call plsdev(dev) 
          goto 10    !replot
      elseif(gopt.eq.22)then
	   write(*,'(/15x,''change Z(bottom) axis max value from: '',f8.3)')x2high
	   write(*,'(13x,''to > '',$)')
	   read(*,*)x2high
	   goto 51
      elseif(gopt.eq.23)then
	   write(*,'(/15x,''change Z(bottom) axis min. value from: '',f8.3)')x2low
	   write(*,'(13x,''to > '',$)')
	   read(*,*)x2low
	   goto 51
      elseif(gopt.eq.24)then
	   write(*,'(/15x,''change X(bottom) axis max tick value from: '',f8.3)')mxx2tic
	   write(*,'(13x,''to > '',$)')
	   read(*,*)mxx2tic
	   goto 51
      elseif(gopt.eq.25)then
	   write(*,'(/15x,''change X(bottom) axis min tick value from: '',f8.3)')mnx2tic
	   write(*,'(13x,''to > '',$)')
	   read(*,*)mnx2tic
	   goto 51
      else if(gopt.eq.99)then
         goto 1
      else
        write(*,'(/13x,''unknown option re-enter a valid request'')')
        goto 51
      end if
c
	return
c
991	write(*,'(/15x,''Error reading plot file name'')')
	write(*,'(15x,''Try again and do not forget to append'')')
	write(*,'(15x,''the extension .ps'')')
	goto 51
c
	end
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
	subroutine plt4(mxlen,maxit,rcscrv,nmax,rcnt,mnpoff,flag)
c plot all regional curves and their solutions
	integer mxlen,maxit,rcnt,mnpoff
	real*4 rcscrv(mxlen,2,maxit),flag
c	local
	integer i,p,j,k,nrows,ncols,nplts
	real*4 x(6000),y1(6000),y2(6000)
	character string*16,filename*70,ans*2
c
c PlotStyle variables
	integer*4 gopt,opt,mxvar
	parameter (mxvar=20)
	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
c
1	gopt=99
       call 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
	call plsetopt('geometry','1000x600')          !set default plot window dimension
	call plsdev(dev)
c	
	xlow=0.;xhigh=float(nmax);ylow=0.0
	do k=1,rcnt
	  do j=1,2
	    do p=1,mxlen
	      if(rcscrv(p,j,k).ne.flag.and.rcscrv(p,j,k).gt.yhigh)yhigh=rcscrv(p,j,k)
	    enddo
	  enddo
	enddo
c
	call  ticit(xlow,xhigh,ylow,yhigh,zlow,zhigh,mnxtic,mnytic,mnztic,
     *                    mxxtic,mxytic,mxztic)
c     
10	continue
c
c set background color
c
       if(.not.bg)then
         call plscol0(0,255,255,255)              !change default color map black>white 
         call plscol0(15,0,0,0)                   !change default color map white>black
         call plscolbg(red,green,blue)            !change background color if other than white is desired
       elseif(bg)then
         call plscol0(15,255,255,255)              !change default color map white>black
         call plscol0(0,0,0,0)                   !change default color map black>white
         call plscolbg(red,green,blue)            !change background color if other than white is desired
       endif  
c
	if(rcnt.le.4)then
	   nrows=2;ncols=2
	elseif(rcnt.gt.4.and.rcnt.le.8)then
	   nrows=2;ncols=4
	elseif(rcnt.gt.8.and.rcnt.le.10)then
	   nrows=2;ncols=5
	elseif(rcnt.gt.10.and.rcnt.le.15)then
	   nrows=3;ncols=5
	elseif(rnct.gt.15.and.rcnt.le.20)then
	   nrows=4;ncols=5
	else
	   write(*,'(/1x,''Too many Regional curves to plot. Try '')')
	   write(*,'(1x,''plotting them outside this program.'')')
	   write(*,'(1x,''Hit RETURN to Continue'')')
	   pause
	   return
	endif
c	
	string='Iteration #     '
	nplts=nrows*ncols
c
c initialize plplot
	call plinit()
	call plssub(nrows,ncols)
	do i=1,rcnt
	   j=1
	   do p=1,nmax
	       if(rcscrv(p+mnpoff,1,i).ne.flag)then
	          y1(j)=rcscrv(p+mnpoff,1,i)
	          y2(j)=rcscrv(p+mnpoff,2,i)
	          if(i.eq.1)x(j)=real(p+mnpoff)
	          j=j+1
	       endif
	   enddo
	   j=j-1
	   call plcol0(15)   !color box and lables
	   call pladv(0) 
          call plwid(1)
	   call plvpor(0.125,0.85,0.2,0.7)  !top plot window
	   call plwind(xlow,xhigh,ylow,yhigh)
	   call plaxes (xlow,ylow,'abitnr',mxxtic,mnxtic,'abinstv',mxytic,mnytic)
	   if(i.eq.1)then
	       call pllab('Biological Year','Y','Initial RC and Fit')
	   else
	      write(string(14:16),'(i3)')i-1
	      call pllab('Biological Year','Y',string)
	   endif
	   call plcol0(colline(1))
	   call plwid(1)	     
	   call plline(j,x,y1)
	   call plcol0(1)   !color box and lables
	   call plwid(colline(2))	     
	   call plline(j,x,y2)
	enddo
c
	if(rcnt.lt.nplts)goto 20
c
20	call plend()	    	    
c	
       ans='C '
51	write(*,'(//15x,''|************* plot options menu **************|'')')
       write(*,'(15x,''| replot             [0]  minor ticks y   [11] |'')')
	write(*,'(15x,''| background color   [1]  major ticks z    [-] |'')')
 	write(*,'(15x,''| frame color        [-]  minor ticks z    [-] |'')')
	write(*,'(15x,''| text color         [-]  max. x          [14] |'')')
	write(*,'(15x,''| line color         [4]  min. x          [15] |'')')
       write(*,'(15x,''| curve color        [5]  max. y          [16] |'')')
       write(*,'(15x,''| line style         [-]  min. y          [17] |'')')
       write(*,'(15x,''| curve width        [-]  max. z           [-] |'')')
       write(*,'(15x,''| major ticks x      [8]  min. z           [-] |'')')
       write(*,'(15x,''| minor ticks x      [9]  symbol type      [-] |'')')
       write(*,'(15x,''| major ticks y     [10]  symbol color     [-] |'')')
	write(*,'(15x,''|                                              |'')')
	write(*,'(15x,''|              reset options  [99]             |'')')
	write(*,'(15x,''|----------------------------------------------|'')')
       write(*,'(15x,''|    [s]ave   <[c]ontinue>  [n]o more plots    |'')') 
       write(*,'(15x,''|______________________________________________|'')')
	write(*,'(/15x,'' enter option number > '',$)')
       read(*,'(a2)',err=51)ans
       if((ans.eq.'S ').or.(ans.eq.'s '))then
         write(*,'(/15x,''NOTE: The image file you are about to create is PostScript. '')')
         write(*,'(15x,''To make this readily apparent to your OS we recommend adding'')')
         write(*,'(15x,''the extension .ps to the file name.'')')
         call blank(filename)
         write(*,'(15x,''Enter plot file name > '',$)')
         read(*,'(a70)',err=991)filename   
         call lalign(filename)
	  call plsetopt('geometry','600x800')          !change default plot window dimension for printing only
	  call plsdev('psc')	  
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'C ').or.(ans.eq.'c ').or.(ans.eq.'  ').or.
     *                             (ans.eq.'Y ').or.(ans.eq.'y '))then
         return
       elseif((ans.eq.'N ').or.(ans.eq.'n '))then
         return
       else
         read(ans(1:2),'(i2)',err=51)gopt     !convert ans to gopt then continue
       endif
       if((gopt.gt.0).and.(gopt.le.21))then
         call 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)                         
         goto 51  !50
       else if(gopt.eq.0)then
          dev='xwin'   !set plot output device back to screen
	   call plsetopt('geometry','1000x600')          !set default plot window dimension
	   call plsdev(dev) 
          goto 10    !replot
       else if(gopt.eq.99)then
         goto 1
       else
        write(*,'(/13x,''unknown option re-enter a valid request'')')
        goto 51
       end if
c
	return
c
991	write(*,'(/15x,''Error reading plot file name'')')
	write(*,'(15x,''Try again and do not forget to append'')')
	write(*,'(15x,''the extension .ps'')')
	goto 51
c
	end
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
	subroutine plt5(mxlen,maxit,rcscrv,nmax,rcnt,mnpoff,flag)
c plot all regional curves in a stacked plot.

	integer mxlen,maxit,rcnt,mnpoff
	real*4 rcscrv(mxlen,2,maxit),flag
c	local
	integer i,p,j,k,nrows,ncols,nplts
	real*4 x(6000),y1(6000),y2(6000)
	character string*16,filename*70,ans*2
c
c PlotStyle variables
	integer*4 gopt,opt,mxvar
	parameter (mxvar=20)
	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
c
1	gopt=99
       call 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
	colline(1)=1; colline(2)=9
c	
	 xlow=0.;xhigh=float(nmax)
	 do k=1,rcnt
	   do j=1,2
	     do p=1,mxlen
	       if(rcscrv(p,j,k).ne.flag)then
	         if(rcscrv(p,j,k).gt.yhigh)yhigh=rcscrv(p,j,k)
	         if(rcscrv(p,j,k).lt.ylow.and.rcscrv(p,j,k).ne.0.0)ylow=rcscrv(p,j,k)
	       endif
	     enddo
	   enddo
	 enddo
c
	call  ticit(xlow,xhigh,ylow,yhigh,zlow,zhigh,mnxtic,mnytic,mnztic,
     *                    mxxtic,mxytic,mxztic)
c	
	 string='Iteration #     '
	 nplts=nrows*ncols
c
	call plsetopt('geometry','1000x600')          !set default plot window dimension
	call plsdev(dev)
c
10	continue
c
c set background color
c
      if(.not.bg)then
        call plscol0(0,255,255,255)              !change default color map black>white 
        call plscol0(15,0,0,0)                   !change default color map white>black
        call plscolbg(red,green,blue)            !change background color if other than white is desired
      elseif(bg)then
        call plscol0(15,255,255,255)              !change default color map white>black
        call plscol0(0,0,0,0)                   !change default color map black>white
        call plscolbg(red,green,blue)            !change background color if other than white is desired
      endif  
c
c initialize plplot
	call plinit()
	call plssub(1,1)
	call plcol0(15)   !color box and lables
	call plwid(1)
	call pladv(0) 
	call plvpor(0.125,0.92,0.15,0.85)  !top plot window
	call plwind(xlow,xhigh+10.,ylow,yhigh)
	call plaxes (xlow,ylow,'abitnr',mxxtic,mnxtic,'abinstv',mxytic,mnytic)
	call pllab('Biological Year','Y','Regional Curves')
	call plcol0(colline(1))   !color box and lables
	call plmtex('b',-26.5,0.41,0.0,'Initial')
	call plcol0(colline(2))
	call plmtex('b',-26.5,0.49,0.0,'/Final')
	do i=1,rcnt
	     call plcol0(15)
	     k=1
	     do p=1,nmax
	 	  if(rcscrv(p,1,i).ne.flag.or.rcscrv(p,1,i).ne.0.)then
	 	    y1(k)=rcscrv(p+mnpoff,1,i)
	           y2(k)=rcscrv(p+mnpoff,2,i)
	           if(i.eq.1)x(k)=real(p+mnpoff)
	           k=k+1
	         endif
	     enddo
	     k=k-1
	     if(i.eq.1)call plcol0(colline(1))
	     if(i.eq.rcnt)call plcol0(colline(2))   !color box and lables
	     call plline(k,x,y1)
	enddo
c
   	call plend()	    	    
c	
       ans='C '
51	write(*,'(//15x,''|************* plot options menu **************|'')')
       write(*,'(15x,''| replot             [0]  minor ticks y   [11] |'')')
	write(*,'(15x,''| background color   [1]  major ticks z    [-] |'')')
 	write(*,'(15x,''| frame color        [-]  minor ticks z    [-] |'')')
	write(*,'(15x,''| text color         [-]  max. x          [14] |'')')
	write(*,'(15x,''| line color         [4]  min. x          [15] |'')')
       write(*,'(15x,''| curve color        [5]  max. y          [16] |'')')
       write(*,'(15x,''| line style         [-]  min. y          [17] |'')')
       write(*,'(15x,''| curve width        [-]  max. z           [-] |'')')
       write(*,'(15x,''| major ticks x      [8]  min. z           [-] |'')')
       write(*,'(15x,''| minor ticks x      [9]  symbol type      [-] |'')')
       write(*,'(15x,''| major ticks y     [10]  symbol color     [-] |'')')
	write(*,'(15x,''|                                              |'')')
	write(*,'(15x,''|              reset options  [99]             |'')')
	write(*,'(15x,''|----------------------------------------------|'')')
       write(*,'(15x,''|    [s]ave   <[c]ontinue>  [n]o more plots    |'')') 
       write(*,'(15x,''|______________________________________________|'')')
	write(*,'(/15x,'' enter option number > '',$)')
       read(*,'(a2)',err=51)ans
       if((ans.eq.'S ').or.(ans.eq.'s '))then
         write(*,'(/15x,''NOTE: The image file you are about to create is PostScript. '')')
         write(*,'(15x,''To make this readily apparent to your OS we recommend adding'')')
         write(*,'(15x,''the extension .ps to the file name.'')')
         call blank(filename)
         write(*,'(15x,''Enter plot file name > '',$)')
         read(*,'(a70)',err=991)filename   
         call lalign(filename)
	  call plsetopt('geometry','600x800')          !change default plot window dimension for printing only
	  call plsdev('psc')	  
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'C ').or.(ans.eq.'c ').or.(ans.eq.'  ').or.
     *                             (ans.eq.'Y ').or.(ans.eq.'y '))then
         return
       elseif((ans.eq.'N ').or.(ans.eq.'n '))then
         return
       else
         read(ans(1:2),'(i2)',err=51)gopt     !convert ans to gopt then continue
       endif
       if((gopt.gt.0).and.(gopt.le.21))then
         call 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)                         
         goto 51  !50
       else if(gopt.eq.0)then
          dev='xwin'   !set plot output device back to screen
	   call plsetopt('geometry','1000x600')          !set default plot window dimension
	   call plsdev(dev) 
          goto 10    !replot
       else if(gopt.eq.99)then
         goto 1
       else
        write(*,'(/13x,''unknown option re-enter a valid request'')')
        goto 51
       end if
c
	return
c
991	write(*,'(/15x,''Error reading plot file name'')')
	write(*,'(15x,''Try again and do not forget to append'')')
	write(*,'(15x,''the extension .ps'')')
	goto 51
c
	end
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
	subroutine plt6(mxl,mxs,nc,n,btout2,string1,string2)
c plot power spectrum of std and SSF chronologies in Log10
c argument decs
	integer mxl,mxs,nc,n
	real*4 btout2(mxl,3)
	character*18 string1,string2
c local decs
	integer p,j
	real*4 step
	real*4 wrk1(6000),wrk2(6000),wrk3(6000)
	character ans*2,filename*70
c
c PlotStyle variables
	integer*4 gopt,opt,mxvar
	parameter (mxvar=20)
	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
c
1	gopt=99
       call 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 set default line colors     
       colline(1)=9;colline(2)=1
c
	call plsetopt('geometry','1000x600')          !set default plot window dimension
	call plsdev(dev)
c
	do p=1,nc
	  do j=1,n
	     if(p.eq.1)then
	       if(btout2(j,p).gt.xhigh)xhigh=btout2(j,p)
	       if(btout2(j,p).lt.xlow)xlow=btout2(j,p)
	       wrk1(j)=btout2(j,p)
	     else
	       if(log10(btout2(j,p)).gt.yhigh)yhigh=log10(btout2(j,p))
	       if(log10(btout2(j,p)).lt.ylow)ylow=log10(btout2(j,p))
	       if(p.eq.2)wrk2(j)=log10(btout2(j,p))
	       if(p.eq.3)wrk3(j)=log10(btout2(j,p))
	     endif
	  enddo
	enddo
c
c
	call  ticit(xlow,xhigh,ylow,yhigh,zlow,zhigh,mnxtic,mnytic,mnztic,
     *                    mxxtic,mxytic,mxztic)
c	
10	continue
c	
c set background color
       if(.not.bg)then
         call plscol0(0,255,255,255)              !change default color map black>white 
         call plscol0(15,0,0,0)                   !change default color map white>black
         call plscolbg(red,green,blue)            !change background color if other than white is desired
       elseif(bg)then
         call plscol0(15,255,255,255)             !change default color map white>black
         call plscol0(0,0,0,0)                    !change default color map black>white
         call plscolbg(red,green,blue)            !change background color if other than white is desired
       endif  
c initialize plplot
	call plinit()
	call plssub(1,1)
       call plwid(1)
	call plcol0(15)   !color box and lables
	call pladv(0) 
	call plvpor(0.125,0.92,0.15,0.85)  !top plot window
	call plwind(xlow,xhigh,ylow,yhigh)
	call plaxes (xlow,ylow,'abitnr',mxxtic,mnxtic,'abinstv',mxytic,mnytic)
	call pllab('Frequency (cycles/yr.)','log10 Power',' ')
	call plcol0(colline(1))   !9
	step=-43.25
	call plmtex('rv',step,1.065,0.0,string1)
	call plline(n,wrk1,wrk2)
	step=step+24.;call plcol0(colline(2))   !1
	call plmtex('rv',step,1.065,0.0,string2)
	call plline(n,wrk1,wrk3)
c		
	call plend()	    	    
c	
       ans='C '
51	write(*,'(//15x,''|************* plot options menu **************|'')')
       write(*,'(15x,''| replot             [0]  minor ticks y   [11] |'')')
	write(*,'(15x,''| background color   [1]  major ticks z    [-] |'')')
 	write(*,'(15x,''| frame color        [-]  minor ticks z    [-] |'')')
	write(*,'(15x,''| text color         [-]  max. x          [14] |'')')
	write(*,'(15x,''| line color         [4]  min. x          [15] |'')')
       write(*,'(15x,''| curve color        [5]  max. y          [16] |'')')
       write(*,'(15x,''| line style         [-]  min. y          [17] |'')')
       write(*,'(15x,''| curve width        [-]  max. z           [-] |'')')
       write(*,'(15x,''| major ticks x      [8]  min. z           [-] |'')')
       write(*,'(15x,''| minor ticks x      [9]  symbol type      [-] |'')')
       write(*,'(15x,''| major ticks y     [10]  symbol color     [-] |'')')
	write(*,'(15x,''|                                              |'')')
	write(*,'(15x,''|              reset options  [99]             |'')')
	write(*,'(15x,''|----------------------------------------------|'')')
       write(*,'(15x,''|    [s]ave   <[c]ontinue>  [n]o more plots    |'')') 
       write(*,'(15x,''|______________________________________________|'')')
	write(*,'(/15x,'' enter option number > '',$)')
       read(*,'(a2)',err=51)ans
       if((ans.eq.'S ').or.(ans.eq.'s '))then
         write(*,'(/15x,''NOTE: The image file you are about to create is PostScript. '')')
         write(*,'(15x,''To make this readily apparent to your OS we recommend adding'')')
         write(*,'(15x,''the extension .ps to the file name.'')')
         call blank(filename)
         write(*,'(15x,''Enter plot file name > '',$)')
         read(*,'(a70)',err=991)filename   
         call lalign(filename)
	  call plsetopt('geometry','600x800')          !change default plot window dimension for printing only
	  call plsdev('psc')	  
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'C ').or.(ans.eq.'c ').or.(ans.eq.'  ').or.
     *                             (ans.eq.'Y ').or.(ans.eq.'y '))then
         return
       elseif((ans.eq.'N ').or.(ans.eq.'n '))then
         return
       else
         read(ans(1:2),'(i2)',err=51)gopt     !convert ans to gopt then continue
       endif
       if((gopt.gt.0).and.(gopt.le.21))then
         call 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)                         
         goto 51  
       else if(gopt.eq.0)then
          dev='xwin'   !set plot output device back to screen
	   call plsetopt('geometry','1000x600')        !set default plot window dimension
	   call plsdev(dev) 
          goto 10    !replot
       else if(gopt.eq.99)then
         goto 1
       else
        write(*,'(/13x,''unknown option re-enter a valid request'')')
        goto 51
       end if
c
	return
c
991	write(*,'(/15x,''Error reading plot file name'')')
	write(*,'(15x,''Try again and do not forget to append'')')
	write(*,'(15x,''the extension .ps'')')
	goto 51
c
	end
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
*sbr spaghetti
*
      subroutine spaghetti(xy,rline,ny,ns,ify,xlab,ylab,tit,annot1,annot2,mxy,mxs,iplt)
c
c     argument
       real*4 xy(mxy,mxs),rline(mxy)
       integer ny,ns,ify,mxy,mxs,iplt
       character tit*60,xlab*20,ylab*20,annot1*36,annot2*36
c     local
	integer mxlen,i,j
       parameter(mxlen=6000)
       real*4 x(mxlen),wrk(mxlen)	
       character filename*70,ans*2
c
c PlotStyle variables
	integer*4 gopt,opt,mxvar
	parameter (mxvar=20)
	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
1	gopt=99
       call 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

       do i=1,ny
        do j=1,ns
          datum=xy(i,j)
          if(datum.ne.-999.0)then
            if(datum.gt.yhigh)yhigh=datum
            if(datum.lt.ylow)ylow=datum
          endif
        enddo
        x(i)=ify+i-1
       enddo
cc       range=yhigh-ylow
cc       yhigh=yhigh+range/20.
cc       ylow=ylow-range/20.
c
       xlow=ify; xhigh=ify+ny-1
c
	call  ticit(xlow,xhigh,ylow,yhigh,zlow,zhigh,mnxtic,mnytic,mnztic,
     *                    mxxtic,mxytic,mxztic)
c	
       if(iplt.eq.3)yhigh=0.01  !defaul ymax for interation difference plots

	colline(1)=15;colline(2)=1    !
	call plsetopt('geometry','1000x600')          !set default plot window dimension
       call plsdev('xwin')
c      
   10  continue
c
c set background color
c
       if(.not.bg)then
        call plscol0(0,255,255,255)              !change default color map black>white 
        call plscol0(15,0,0,0)                   !change default color map white>black
        call plscolbg(red,green,blue)            !change background color if other than white is desired
       elseif(bg)then
        call plscol0(15,255,255,255)              !change default color map white>black
        call plscol0(0,0,0,0)                   !change default color map black>white
        call plscolbg(red,green,blue)            !change background color if other than white is desired
       endif  
c
c *** initialize plplot
       call plinit()
c *** set lable color
       call plcol0(15)   !color box and lables
c *** set curve width
       call plwid(1)
c *** define the viewport one column by one rows
       call plssub(1,1)
       call plfont(1)
c
	call pladv(0) 
	call plvpor(0.125,0.92,0.15,0.85)  !top plot window
	call plwind(xlow,xhigh,ylow,yhigh)
	call plaxes (xlow,ylow,'abitnr',mxxtic,mnxtic,'abinstv',mxytic,mnytic)
c	
       call pllab(xlab,ylab,' ')
       call plmtex('b',-30.,.5,0.5,tit)
c *** set line style
       call pllsty(1)
c *** set line color
       call plcol0(15)  !color lines
c *** do plots
       if(rline(1).ne.-999.9)then
         do i=1,ny
           x(i)=xlow+i-1
         enddo
         call plline(ny,x,rline)            !plot rline
       endif
       do j=1,ns
         do i=1,ny
           wrk(i)=xy(i,j)
         enddo
         call plcol0(colline(1))           !(15)
         if(j.eq.1)then
           call plcol0(9)
           if(ylab.eq.'Biweights')call plwid(1)
         elseif(j.eq.ns)then
           call plcol0(colline(2))          !(1)
           if(ylab.eq.'Biweights')call plwid(1)
         endif
         call plline(ny,x,wrk)
       enddo
       call plcol0(9)
       call plmtex('b',-28.,0.2,0.0,annot1)
       call plcol0(1)   !red
       call plmtex('b',-28.,0.55,0.0,annot2)
c
c *** end plotting
       call plend()  
c
       ans='C '
51	write(*,'(//15x,''|************* plot options menu **************|'')')
       write(*,'(15x,''| replot             [0]  minor ticks y   [11] |'')')
	write(*,'(15x,''| background color   [1]  major ticks z    [-] |'')')
 	write(*,'(15x,''| frame color        [-]  minor ticks z    [-] |'')')
	write(*,'(15x,''| text color         [-]  max. x          [14] |'')')
	write(*,'(15x,''| line color         [4]  min. x          [15] |'')')
       write(*,'(15x,''| curve color        [5]  max. y          [16] |'')')
       write(*,'(15x,''| line style         [-]  min. y          [17] |'')')
       write(*,'(15x,''| curve width        [-]  max. z           [-] |'')')
       write(*,'(15x,''| major ticks x      [8]  min. z           [-] |'')')
       write(*,'(15x,''| minor ticks x      [9]  symbol type      [-] |'')')
       write(*,'(15x,''| major ticks y     [10]  symbol color     [-] |'')')
	write(*,'(15x,''|                                              |'')')
	write(*,'(15x,''|              reset options  [99]             |'')')
	write(*,'(15x,''|----------------------------------------------|'')')
       write(*,'(15x,''|    [s]ave   <[c]ontinue>  [n]o more plots    |'')') 
       write(*,'(15x,''|______________________________________________|'')')
	write(*,'(/15x,'' enter option number > '',$)')
       read(*,'(a2)',err=51)ans
       if((ans.eq.'S ').or.(ans.eq.'s '))then
         write(*,'(/15x,''NOTE: The image file you are about to create is PostScript. '')')
         write(*,'(15x,''To make this readily apparent to your OS we recommend adding'')')
         write(*,'(15x,''the extension .ps to the file name.'')')
         call blank(filename)
         write(*,'(15x,''Enter plot file name > '',$)')
         read(*,'(a70)',err=991)filename   
         call lalign(filename)
	  call plsetopt('geometry','600x800')          !change default plot window dimension for printing only
	  call plsdev('psc')	  
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'C ').or.(ans.eq.'c ').or.(ans.eq.'  ').or.
     *                             (ans.eq.'Y ').or.(ans.eq.'y '))then
         return
       elseif((ans.eq.'N ').or.(ans.eq.'n '))then
         return
       else
         read(ans(1:2),'(i2)',err=51)gopt     !convert ans to gopt then continue
       endif
       if((gopt.gt.0).and.(gopt.le.21))then
         call 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)                         
         goto 51  
       else if(gopt.eq.0)then
          dev='xwin'   !set plot output device back to screen
	   call plsetopt('geometry','1000x600')          !set default plot window dimension
	   call plsdev(dev) 
          goto 10    !replot
       else if(gopt.eq.99)then
         goto 1
       else
        write(*,'(/13x,''unknown option re-enter a valid request'')')
        goto 51
       end if
c
	return
c
991	write(*,'(/15x,''Error reading plot file name'')')
	write(*,'(15x,''Try again and do not forget to append'')')
	write(*,'(15x,''the extension .ps'')')
	goto 51
c
	end
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
	subroutine scatplt(mxy,mxs,x1,y1,slope,int1,num,nc,n2,xtmp,rho,int2,slp)
c create a scatter plot of x vs y and thier ols solution
	integer mxy,mxs,num(mxs),nc,n2
	real*4 x1(mxy,mxs),y1(mxy,mxs),slope(mxs),int1(mxs),xtmp(mxy*mxs),rho,int2,slp
c	local
	integer p,j,k
	real*4 x2(6000),y2(6000),y3(6000)
	character string*55,ans*2,filename*70
c
c PlotStyle variables
	integer*4 gopt,opt,mxvar
	parameter (mxvar=20)
	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
1	gopt=99
       call 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
	colline(1)=15;colline(2)=1    !
c	
	do k=1,nc
	   do p=1,num(k)
	      if(y1(p,k).gt.yhigh)yhigh=y1(p,k)
	      if(y1(p,k).lt.ylow)ylow=y1(p,k)
	      if(x1(p,k).gt.xhigh)xhigh=x1(p,k)
	      if(x1(p,k).lt.xlow)xlow=x1(p,k)
	      j=j+1
	  enddo
	enddo       
c
	call  ticit(xlow,xhigh,ylow,yhigh,zlow,zhigh,mnxtic,mnytic,mnztic,
     *                    mxxtic,mxytic,mxztic)
c		
	write(*,'(/1x,''from scatplt'')')       
c
	call plsetopt('geometry','1000x600')          !set default plot window dimension
	call plsdev(dev)

10	continue
c
c set background color
c
       if(.not.bg)then
        call plscol0(0,255,255,255)              !change default color map black>white 
        call plscol0(15,0,0,0)                   !change default color map white>black
        call plscolbg(red,green,blue)            !change background color if other than white is desired
       elseif(bg)then
        call plscol0(15,255,255,255)             !change default color map white>black
        call plscol0(0,0,0,0)                    !change default color map black>white
        call plscolbg(red,green,blue)            !change background color if other than white is desired
       endif  
c
c initialize plplot
	call plinit()
	call plssub(1,1)
       call plwid(1)
	call plcol0(15)   !color box and lables
	call pladv(0) 
	call plvpor(0.125,0.92,0.15,0.85)  !top plot window
	call plwind(xlow,xhigh,ylow,yhigh)
	call plaxes (xlow,ylow,'abitnr',mxxtic,mnxtic,'abinstv',mxytic,mnytic)	
cccc	call plenv(minx,maxx,miny-1.,maxy+1.5,0,2)
       string='Y=       +       x  Rho=             '
       write(string,*)'Y=',int2,' + ',slp,'(x)  Rho= ',rho
	call pllab('log(LEVEL)','log(SPREAD)',string)
	do k=1,nc
	    call plcol0(colline(1))
	    do p=1,num(k)
	       x2(p)=x1(p,k)
	       y2(p)=y1(p,k)
	    enddo
           call plwid(2)
	    call plpoin(num(k),x2,y2,1)
	    call plcol0(colline(2))
	    do p=1,num(k)
	      y3(p)=x2(p)*slope(k)+int1(k)
	    enddo
ccc           call plwid(1)
	    call plline(num(k),x2,y3)
	enddo
c		
	call plend()	    	    
c	
       ans='C '
51	write(*,'(//15x,''|************* plot options menu **************|'')')
       write(*,'(15x,''| replot             [0]  minor ticks y   [11] |'')')
	write(*,'(15x,''| background color   [1]  major ticks z    [-] |'')')
 	write(*,'(15x,''| frame color        [-]  minor ticks z    [-] |'')')
	write(*,'(15x,''| text color         [-]  max. x          [14] |'')')
	write(*,'(15x,''| line color         [4]  min. x          [15] |'')')
       write(*,'(15x,''| curve color        [5]  max. y          [16] |'')')
       write(*,'(15x,''| line style         [-]  min. y          [17] |'')')
       write(*,'(15x,''| curve width        [-]  max. z           [-] |'')')
       write(*,'(15x,''| major ticks x      [8]  min. z           [-] |'')')
       write(*,'(15x,''| minor ticks x      [9]  symbol type      [-] |'')')
       write(*,'(15x,''| major ticks y     [10]  symbol color     [-] |'')')
	write(*,'(15x,''|                                              |'')')
	write(*,'(15x,''|              reset options  [99]             |'')')
	write(*,'(15x,''|----------------------------------------------|'')')
       write(*,'(15x,''|    [s]ave   <[c]ontinue>  [n]o more plots    |'')') 
       write(*,'(15x,''|______________________________________________|'')')
	write(*,'(/15x,'' enter option number > '',$)')
       read(*,'(a2)',err=51)ans
       if((ans.eq.'S ').or.(ans.eq.'s '))then
         write(*,'(/15x,''NOTE: The image file you are about to create is PostScript. '')')
         write(*,'(15x,''To make this readily apparent to your OS we recommend adding'')')
         write(*,'(15x,''the extension .ps to the file name.'')')
         call blank(filename)
         write(*,'(15x,''Enter plot file name > '',$)')
         read(*,'(a70)',err=991)filename   
         call lalign(filename)
	  call plsetopt('geometry','600x800')          !change default plot window dimension for printing only
	  call plsdev('psc')	  
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'C ').or.(ans.eq.'c ').or.(ans.eq.'  ').or.
     *                             (ans.eq.'Y ').or.(ans.eq.'y '))then
         return
       elseif((ans.eq.'N ').or.(ans.eq.'n '))then
         return
       else
         read(ans(1:2),'(i2)',err=51)gopt     !convert ans to gopt then continue
       endif
       if((gopt.gt.0).and.(gopt.le.21))then
         call 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)                         
         goto 51  
       else if(gopt.eq.0)then
          dev='xwin'   !set plot output device back to screen
	   call plsetopt('geometry','1000x600')          !set default plot window dimension
	   call plsdev(dev) 
          goto 10    !replot
       else if(gopt.eq.99)then
         goto 1
       else
        write(*,'(/13x,''unknown option re-enter a valid request'')')
        goto 51
       end if
c
	return
c
991	write(*,'(/15x,''Error reading plot file name'')')
	write(*,'(15x,''Try again and do not forget to append'')')
	write(*,'(15x,''the extension .ps'')')
	goto 51
c
	end
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
*sbr linguine2
*
      subroutine linguine2(x1,x2,rline,ns,idate,xlab,ylab,tit,annot1,annot2,mxy1,mxs1,mxs)
c
c     write(winu9,'(/13x,''COLOR TABLE ______________________________________________'')')
c     write(winu9,'(13x,''White(0) Red(1)  Yellow(2)  Green(3)  Aquamarine(4) Pink(5) '')')
c     write(winu9,'(13x,''Wheat(6)  Grey(7)  Browm(8)  Blue(9)  BlueViolet(10)'')')
c     write(winu9,'(13x,''Cyan(11)  Turquoise(12)  Magenta(13)  Salmon(14)  Black(15)'')')
c     write(winu9,'(13x,''___________________________________________________________'',/)')
c
      parameter(mxlen=6000)
c     argument
      real*4 x1(mxy1,mxs1),x2(mxy1,mxs1),rline(mxy1)
      integer ny,ns,ify,mxs,idate(mxs,3)
      character tit*60,xlab*20,ylab*20,annot1*36,annot2*36
c     local
      integer i,j
      real*4 x(mxlen),wrk(mxlen),range,ylow1,yhigh1,ylow2,yhigh2	
c      
      character filename*70,ans*2
c
c PlotStyle variables
	integer*4 gopt,opt,mxvar
	parameter (mxvar=20)
	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
1	gopt=99
       call 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
	colline(1)=15;colline(2)=1    !
c
      xlow=100000.0
      xhigh=-100000.0
      ylow1=100000.0
      yhigh1=-100000.0
      do j=1,ns
        ify=idate(j,1)
        ily=idate(j,2)
        ny=ily-ify+1
        if(ify.lt.xlow)xlow=ify
        if(ily.gt.xhigh)xhigh=ily
        do i=1,ny
          datum=x1(i,j)
          if(datum.ne.-999.0)then
            if(datum.gt.yhigh1)yhigh1=datum
            if(datum.lt.ylow1)ylow1=datum
          endif
        enddo
      enddo
      ylow2=100000.0
      yhigh2=-100000.0
      do j=1,ns
        ify=idate(j,1)
        ily=idate(j,2)
        ny=ily-ify+1
        do i=1,ny
          datum=x2(i,j)
          if(datum.ne.-999.0)then
            if(datum.gt.yhigh2)yhigh2=datum
            if(datum.lt.ylow2)ylow2=datum
          endif
        enddo
      enddo
      ylow=amin1(ylow1,ylow2)
      yhigh=amax1(yhigh1,yhigh2)
ccc      write(*,'(1x,''ylow1,yhigh1,ylow2,yhigh2,ylow,yhigh: '',6f8.3)')ylow1,yhigh1,ylow2,yhigh2,ylow,yhigh
      range=yhigh-ylow
      yhigh=yhigh+range/10.
      ylow=ylow-range/10.
      if(ylow.lt.0)ylow=0.0
c
	call  ticit(xlow,xhigh,ylow,yhigh,zlow,zhigh,mnxtic,mnytic,mnztic,
     *                    mxxtic,mxytic,mxztic)
c		
	call plsetopt('geometry','1000x600')          !set default plot window dimension
       call plsdev('xwin')
c
10	continue
c
c set background color
c
      if(.not.bg)then
        call plscol0(0,255,255,255)              !change default color map black>white 
        call plscol0(15,0,0,0)                   !change default color map white>black
        call plscolbg(red,green,blue)            !change background color if other than white is desired
      elseif(bg)then
        call plscol0(15,255,255,255)              !change default color map white>black
        call plscol0(0,0,0,0)                   !change default color map black>white
        call plscolbg(red,green,blue)            !change background color if other than white is desired
      endif  
c
c *** initialize plplot
      call plinit()
c *** set lable color
      call plcol0(15)   !color box and lables
c *** set curve width
      call plwid(1)
c *** define the viewport one column by one rows
      call plssub(1,1)
	call pladv(0) 
	call plvpor(0.125,0.92,0.15,0.85)  !top plot window
	call plwind(xlow,xhigh,ylow,yhigh)
	call plaxes (xlow,ylow,'abitnr',mxxtic,mnxtic,'abinstv',mxytic,mnytic)	
cccc      call plenv(xlow,xhigh,ylow,yhigh,0,0)
      call plfont(1)
      call pllab(xlab,ylab,' ')
      call plmtex('b',-30.,.5,0.5,tit)
c *** set line style
      call pllsty(1)
c *** do plots
      call plcol0(9)
      do j=1,ns
        ify=idate(j,1)
        ily=idate(j,2)
        ny=ily-ify+1
        do i=1,ny
          wrk(i)=x1(i,j)
          x(i)=ify+i-1
        enddo
        call plline(ny,x,wrk)
      enddo
      call plcol0(1)
      do j=1,ns
        ify=idate(j,1)
        ily=idate(j,2)
        ny=ily-ify+1
        do i=1,ny
          wrk(i)=x2(i,j)
          x(i)=ify+i-1
        enddo
        call plline(ny,x,wrk)
      enddo
      call plwid(2)
      call plcol0(15)
      if(rline(1).ne.-999.9)then
        maxn=idate(ns+1,2)-idate(ns+1,1)+1
        do i=1,maxn
          x(i)=idate(ns+1,1)+i-1
        enddo
        call plline(maxn,x,rline)            !plot rline
      endif
      call plcol0(9)  !color lines
      call plwid(1)
      call plmtex('b',-28.,0.12,0.0,annot1)
      call plcol0(1)
      call plmtex('b',-28.,0.65,0.0,annot2)
c
c *** end plotting
c
      call plend()   
c  
       ans='C '
51	write(*,'(//15x,''|************* plot options menu **************|'')')
       write(*,'(15x,''| replot             [0]  minor ticks y   [11] |'')')
	write(*,'(15x,''| background color   [1]  major ticks z    [-] |'')')
 	write(*,'(15x,''| frame color        [-]  minor ticks z    [-] |'')')
	write(*,'(15x,''| text color         [-]  max. x          [14] |'')')
	write(*,'(15x,''| line color         [4]  min. x          [15] |'')')
       write(*,'(15x,''| curve color        [5]  max. y          [16] |'')')
       write(*,'(15x,''| line style         [-]  min. y          [17] |'')')
       write(*,'(15x,''| curve width        [-]  max. z           [-] |'')')
       write(*,'(15x,''| major ticks x      [8]  min. z           [-] |'')')
       write(*,'(15x,''| minor ticks x      [9]  symbol type      [-] |'')')
       write(*,'(15x,''| major ticks y     [10]  symbol color     [-] |'')')
	write(*,'(15x,''|                                              |'')')
	write(*,'(15x,''|              reset options  [99]             |'')')
	write(*,'(15x,''|----------------------------------------------|'')')
       write(*,'(15x,''|    [s]ave   <[c]ontinue>  [n]o more plots    |'')') 
       write(*,'(15x,''|______________________________________________|'')')
	write(*,'(/15x,'' enter option number > '',$)')
       read(*,'(a2)',err=51)ans
       if((ans.eq.'S ').or.(ans.eq.'s '))then
         write(*,'(/15x,''NOTE: The image file you are about to create is PostScript. '')')
         write(*,'(15x,''To make this readily apparent to your OS we recommend adding'')')
         write(*,'(15x,''the extension .ps to the file name.'')')
         call blank(filename)
         write(*,'(15x,''Enter plot file name > '',$)')
         read(*,'(a70)',err=991)filename   
         call lalign(filename)
	  call plsetopt('geometry','600x800')          !change default plot window dimension for printing only
	  call plsdev('psc')	  
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'C ').or.(ans.eq.'c ').or.(ans.eq.'  ').or.
     *                             (ans.eq.'Y ').or.(ans.eq.'y '))then
         return
       elseif((ans.eq.'N ').or.(ans.eq.'n '))then
         return
       else
         read(ans(1:2),'(i2)',err=51)gopt     !convert ans to gopt then continue
       endif
       if((gopt.gt.0).and.(gopt.le.21))then
         call 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)                         
         goto 51  
       else if(gopt.eq.0)then
          dev='xwin'   !set plot output device back to screen
	   call plsetopt('geometry','1000x600')          !set default plot window dimension
	   call plsdev(dev) 
          goto 10    !replot
       else if(gopt.eq.99)then
         goto 1
       else
        write(*,'(/13x,''unknown option re-enter a valid request'')')
        goto 51
       end if
c
	return
c
991	write(*,'(/15x,''Error reading plot file name'')')
	write(*,'(15x,''Try again and do not forget to append'')')
	write(*,'(15x,''the extension .ps'')')
	goto 51
c
	end
c
c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
