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(9000)	      
      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 arspltstyle(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)    
     
	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  ticit(xlow,xhigh,ylow,yhigh,zlow,zhigh,mnxtic,mnytic,mnztic,
     *                    mxxtic,mxytic,mxztic)
c
	if(iw3.eq.0)ylow=0.
c      
	call plsdev('xwin')
	call plsetopt('geometry','1000x850')          !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     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.1,0.9,0.15,0.9)  !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,' ')
	if(annot1(1:5).eq.'     '.and.annot2(1:5).eq.'     ')then
        call plmtex('b',-35.5,.5,0.5,tit)
	else
        call plmtex('b',-35.5,.5,0.5,tit)
	endif
      
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',-33.75,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',-33.75,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)')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','600x1000')          !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)')gopt     !convert ans to gopt then continue
      endif
      if((gopt.gt.0).and.(gopt.le.21))then
         call arspltstyle(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','1000x800')          !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(9000),wrk2(9000),wrk3(9000)
	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 arspltstyle(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
ccc	if(miny.ge.0.)miny=0.
	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','1000x850')          !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)
ccc	call plenv(real(0),real(lycaly+mnpoff),miny,maxy,0,2)
	call pladv(0) 
	call plvpor(0.1,0.9,0.15,0.9)  !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(1)   !color box and lables
	call plline(p,wrk1,wrk3)
	call plcol0(9)   !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         [-]  min. x          [15] |'')')
       write(*,'(15x,''| curve  color       [-]  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)')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','600x1000')          !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)')gopt     !convert ans to gopt then continue
      endif
      if((gopt.gt.0).and.(gopt.le.21))then
         call arspltstyle(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','1000x800')          !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
	real*4 wrk1(9000),wrk2(9000),wrk3(9000),wrk4(9000)
	character ans*2,filename*70
	logical ok
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 arspltstyle(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
ccc	write(*,'(/1x,''from plt2'')')
c
	call plsetopt('geometry','1000x850')          !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	
	ylow=9999.;yhigh=-9999.;xlow=9999;xhigh=-9999
	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
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 plvpor(0.1,0.9,0.15,0.9)  !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(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 lines
	enddo
c
c set lable color
	call plcol0(15)   !color box and lables
       call plwid(1)
	call plvpor(0.1,0.9,0.15,0.9)  !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,yhigh
	   wrk1(p)=0.;wrk2(p)=0.;wrk3(p)=0
	enddo
	do p=1,nc
	   k=1
          ny=idate(p,2)-idate(p,1)+1
ccc	   do j=idate(p,1),idate(p,2)
	   do j=1,ny
            j1=xlow+j-1
	     wrk2(j1)=wrk2(j1)+pltdata(k,p)
	     wrk3(j1)=wrk3(j1)+1.
	     k=k+1
	   enddo
	   k=k-1
	enddo
	k=1
	do j=xlow,xhigh
	   if(wrk3(j).ne.0)wrk1(k)=wrk2(j)/wrk3(j)
	   wrk4(k)=real(j)
	   k=k+1
	enddo
      	k=k-1
	call plcol0(1)   !color box and lables
	call plline(k,wrk4,wrk1)       !draw line
	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         [-]  min. x          [15] |'')')
       write(*,'(15x,''| curve  color       [-]  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)')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','600x1000')          !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)')gopt     !convert ans to gopt then continue
      endif
      if((gopt.gt.0).and.(gopt.le.21))then
         call arspltstyle(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','1000x800')          !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, minx, maxx
	integer red,blue,green
	real*4 miny, maxy
	real*4 wrk1(9000),wrk2(9000),wrk3(9000)
	character dev*80
	logical ok,bg
c
       dev='xwin';ok=.true.
       red=255;green=255;blue=255
       bg=.false.
c
	  call plsetopt('geometry','1000x600')          !set default plot window dimension
10	if(ok)call plsdev(dev)
ccc	write(*,'(/1x,''from plt3'')')
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	
	miny=9999.;maxy=-9999.;minx=9999;maxx=-9999; k=1
	do p=1,nmax
	   if(xrc(p).ne.flag.and.xrc(p).gt.maxy)maxy=xrc(p)
	   if(f(p).ne.flag.and.f(p).gt.maxy)maxy=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
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 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
	miny=9999.; maxy=-9999.; minx=9999; maxx=-9999; j=idate(sernum,1)
	do p=1,n
	      if(indx(p).ne.flag.and.indx(p).gt.maxy)maxy=indx(p)
	      if(indx(p).ne.flag.and.indx(p).lt.miny)miny=indx(p)
	      wrk1(p)=real(j)
	      j=j+1
	enddo
c
c set lable color
	call plcol0(15)   !color box and lables
       call plwid(1)
	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,wrk1,indx)
	call plend()
c	
       ans='C '
	dev='xwin'
       write(*,'(/1x,''|************* plot options menu ***************|'')')
       write(*,'(1x,''|-----------------------------------------------|'')')
       write(*,'(1x,''| [s]ave  [c]ontinue  [r]eplot  [n]o more plots |'')') 
       write(*,'(1x,''|_______________________________________________|'')')
       write(*,'(/1x,'' enter option number > '',$)')
       read(*,'(a1)')ans
       if((ans.eq.'S').or.(ans.eq.'s'))then
         dev='psc';ok=.false.;filename='fig11.ps'
	  call plsetopt('geometry','600x1000')          !set default plot window dimension for printing only
	  call plsdev(dev)
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'R').or.(ans.eq.'r'))then
         ok=.true.
         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
	endif
c
	return
	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
	integer red,blue,green
	real*4 miny, maxy, minx, maxx
	real*4 x(9000),y1(9000),y2(9000)
	character string*16,dev*3
	logical ok,bg
c
       dev='xwin';ok=.true.
       red=255;green=255;blue=255
       bg=.false.
c
	  call plsetopt('geometry','1000x600')          !set default plot window dimension
10	if(ok)call plsdev(dev)
ccc	write(*,'(/1x,''from plt4'')')
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	
	miny=9999.;maxy=-9999.
	minx=0.;maxx=float(nmax)
	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.maxy)maxy=rcscrv(p,j,k)
	      if( (rcscrv(p,j,k).ne.flag) .and. (rcscrv(p,j,k).lt.miny) .and. 
     *                               (rcscrv(p,j,k).ne.0.0) )miny=rcscrv(p,j,k)
	    enddo
	  enddo
	enddo
c
	if(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 plwid(1)
	         call plenv(real(0),real(j+mnpoff),miny,maxy,0,2)
	         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(9)
	         call plwid(1)	     
	         call plline(j,x,y1)
	         call plcol0(1)   !color box and lables
	         call plwid(2)	     
	         call plline(j,x,y2)
	enddo
c
	if(rcnt.lt.nplts)goto 20
c
20	call plend()	    	    
c	
       ans='C '
	dev='xwin'
       write(*,'(/1x,''|************* plot options menu ***************|'')')
       write(*,'(1x,''|-----------------------------------------------|'')')
       write(*,'(1x,''|       [s]ave   <[c]ontinue>   [r]eplot        |'')') 
       write(*,'(1x,''|_______________________________________________|'')')
       write(*,'(/1x,'' enter option number > '',$)')
       read(*,'(a1)')ans
       if((ans.eq.'S').or.(ans.eq.'s'))then
         dev='psc';ok=.false.;filename='fig11.ps'
	  call plsetopt('geometry','600x1000')          !set default plot window dimension for printing only
	  call plsdev(dev)
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'R').or.(ans.eq.'r'))then
         ok=.true.
         goto 10
       elseif((ans.eq.'C').or.(ans.eq.'c').or.(ans.eq.' ').or.
     *                             (ans.eq.'Y').or.(ans.eq.'y'))then
         return
	endif
c
	return
	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
	     integer red,blue,green
	     real*4 miny, maxy, minx, maxx, step
	     real*4 x(9000),y1(9000),y2(9000)
	     character string*16,dev*3
	     logical ok,bg
c
       dev='xwin';ok=.true.
       red=255;green=255;blue=255
       bg=.false.
c
	  call plsetopt('geometry','1000x600')          !set default plot window dimension
   10	if(ok)call plsdev(dev)
ccc	write(*,'(/1x,''from plt5'')')
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	
	     miny=9999.;maxy=-9999.
	     minx=0.;maxx=float(nmax);n1=1
	     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.maxy)maxy=rcscrv(p,j,k)
	             if(rcscrv(p,j,k).lt.miny.and.rcscrv(p,j,k).ne.0.0)miny=rcscrv(p,j,k)
	           endif
	         enddo
	       enddo
	     enddo
c	
	     string='Iteration #     '
	     nplts=nrows*ncols
c
c initialize plplot
	     call plinit()
	     call plssub(1,1)
	     call plcol0(15)   !color box and lables
	     call plwid(1)
	     call plenv(real(0),maxx+10.,miny,maxy,0,2)
	     call pllab('Biological Year','Y','Regional Curves')
	     call plcol0(9)   !color box and lables
	     step=-38.4
	     call plmtex('rv',step,1.065,0.0,'Initial')
	     step=step+4.;call plcol0(1)
	     call plmtex('rv',step,1.065,0.0,'/Final')
	     call plcol0(15)
	     do i=1,rcnt
	         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
	       call plcol0(15)
	       if(i.eq.1)call plcol0(9)
	       if(i.eq.rcnt)call plcol0(1)   !color box and lables
	       call plline(k,x,y1)
	     enddo
c
   20	call plend()	    	    
c	
      ans='C '
	     dev='xwin'
      write(*,'(/1x,''|************* plot options menu ***************|'')')
      write(*,'(1x,''|-----------------------------------------------|'')')
      write(*,'(1x,''|       [s]ave   <[c]ontinue>   [r]eplot        |'')') 
      write(*,'(1x,''|_______________________________________________|'')')
      write(*,'(/1x,'' enter option number > '',$)')
      read(*,'(a1)')ans
      if((ans.eq.'S').or.(ans.eq.'s'))then
        dev='psc';ok=.false.;filename='fig11.ps'
	  call plsetopt('geometry','600x1000')          !set default plot window dimension for printing only
	 call plsdev(dev)
        call plsfnam(filename)
        goto 10
      elseif((ans.eq.'R').or.(ans.eq.'r'))then
        ok=.true.
        goto 10
      elseif((ans.eq.'C').or.(ans.eq.'c').or.(ans.eq.' ').or.
     *                             (ans.eq.'Y').or.(ans.eq.'y'))then
        return
	     endif
c
	     return
	     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 red,blue,green
	integer p,j,k
	real*4 minx,maxx,miny,maxy,step
	real*4 wrk1(9000),wrk2(9000),wrk3(9000)
	character ans*1,filename*9,dev*80
	logical ok,bg
c
       dev='xwin';ok=.true.
       red=255;green=255;blue=255
       bg=.false.
ccc	write(*,'(/1x,''from plt6'')')
c
	miny=999.;maxy=-999.;minx=miny;maxx=maxy
	do p=1,nc
	  do j=1,n
	     if(p.eq.1)then
	       if(btout2(j,p).gt.maxx)maxx=btout2(j,p)
	       if(btout2(j,p).lt.minx)minx=btout2(j,p)
	       wrk1(j)=btout2(j,p)
	     else
	       if(log10(btout2(j,p)).gt.maxy)maxy=log10(btout2(j,p))
	       if(log10(btout2(j,p)).lt.miny)miny=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
	  call plsetopt('geometry','1000x600')          !set default plot window dimension
10	if(ok)call plsdev(dev)
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 plenv(minx,maxx,miny,maxy,0,20)
	call pllab('Frequency (cycles/yr.)','log10 Power',' ')
	call plcol0(9)
	step=-43.25
	call plmtex('rv',step,1.065,0.0,string1)
	call plline(n,wrk1,wrk2)
	step=step+24.;call plcol0(1)
	call plmtex('rv',step,1.065,0.0,string2)
	call plline(n,wrk1,wrk3)
c		
20	call plend()	    	    
c	
       ans='C '
	dev='xwin'
       write(*,'(/1x,''|************* plot options menu ***************|'')')
       write(*,'(1x,''|-----------------------------------------------|'')')
       write(*,'(1x,''|       [s]ave   <[c]ontinue>   [r]eplot        |'')') 
       write(*,'(1x,''|_______________________________________________|'')')
       write(*,'(/1x,'' enter option number > '',$)')
       read(*,'(a1)')ans
       if((ans.eq.'S').or.(ans.eq.'s'))then
         dev='psc';ok=.false.;filename='fig1b.ps'
	  call plsetopt('geometry','600x1000')          !set default plot window dimension for printing only
	  call plsdev(dev)
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'R').or.(ans.eq.'r'))then
         ok=.true.
         goto 10
       elseif((ans.eq.'C').or.(ans.eq.'c').or.(ans.eq.' ').or.
     *                             (ans.eq.'Y').or.(ans.eq.'y'))then
         return
	endif
c
	return
	end
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
*sbr spaghetti
*
      subroutine spaghetti(xy,rline,ny,ns,ify,xlab,ylab,tit,annot1,annot2,mxy,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=9000)
c     argument
      real*4 xy(mxy,mxs),rline(mxy)
      integer ny,ns,ify,mxy,mxs
      character tit*60,xlab*20,ylab*20,annot1*36,annot2*36
c     local
      integer red,green,blue
      real*4 x(mxlen),wrk(mxlen),miny,maxy,maxx,minx,range	
      integer p
c      
      character dev*80,filename*60,ans*2
      logical bg,ok
c
      mny=100000.0;mxy=-100000.0
      red=255;green=255;blue=255
      bg=.false.;ok=.true.;dev='xwin'
c
      minx=ify
      maxx=ify+ny-1
      maxy=-100000.0
      miny=100000.0
      do i=1,ny
        do j=1,ns
          datum=xy(i,j)
          if(datum.ne.-999.0)then
            if(datum.gt.maxy)maxy=datum
            if(datum.lt.miny)miny=datum
          endif
        enddo
        x(i)=ify+i-1
      enddo
      range=maxy-miny
      maxy=maxy+range/20.
      miny=miny-range/20.
c      
	  call plsetopt('geometry','1000x600')          !set default plot window dimension
   10 if(ok)call plsdev('xwin')
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 plenv(minx,maxx,miny,maxy,0,0)
      call plfont(1)
      call pllab(xlab,ylab,' ')
      call plmtex('b',-35.5,.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)=minx+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(15)
        if(j.eq.1)then
          call plcol0(9)
          if(ylab.eq.'Biweights')call plwid(1)
        elseif(j.eq.ns)then
          call plcol0(1)
          if(ylab.eq.'Biweights')call plwid(1)
        endif
        call plline(ny,x,wrk)
      enddo
      call plcol0(9)
      call plmtex('b',-33.75,0.19,0.0,annot1)
      call plcol0(1)   !red
      call plmtex('b',-33.75,0.55,0.0,annot2)
c
c *** end plotting
c
      call plend()   
c  
       ans='C '
	dev='xwin'
       write(*,'(/1x,''|************* plot options menu ***************|'')')
       write(*,'(1x,''|-----------------------------------------------|'')')
       write(*,'(1x,''|       [s]ave   <[c]ontinue>   [r]eplot        |'')') 
       write(*,'(1x,''|_______________________________________________|'')')
       write(*,'(/1x,'' enter option number > '',$)')
       read(*,'(a1)')ans
       if((ans.eq.'S').or.(ans.eq.'s'))then
         dev='psc';ok=.false.;
         filename=tit
         call stringclean(filename,60)
         do p=1,60
           if(filename(p:p).eq.' ')goto 69
         enddo
69       write(filename(p:p+2),'(a3)')'.ps'
	  call plsetopt('geometry','600x1000')          !set default plot window dimension for printing only
	  call plsdev(dev)
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'R').or.(ans.eq.'r'))then
         ok=.true.
         goto 10
       elseif((ans.eq.'C').or.(ans.eq.'c').or.(ans.eq.' ').or.
     *                             (ans.eq.'Y').or.(ans.eq.'y'))then
         return
	endif
c
      return
      end
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
	integer red,blue,green
	real*4 miny, maxy, minx, maxx
	real*4 x2(9000),y2(9000),y3(9000)
	character string*55,dev*3,filename
	logical ok,bg
c
       dev='xwin';ok=.true.
       red=255;green=255;blue=255
       bg=.false.
ccc	write(*,'(/1x,''from scatplt'')')       
c
	  call plsetopt('geometry','1000x600')          !set default plot window dimension
10	if(ok)call plsdev(dev)
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	
	miny=9999.;maxy=-9999.
	minx=miny ;maxx=maxy 
	do k=1,nc
	   do p=1,num(k)
	      if(y1(p,k).gt.maxy)maxy=y1(p,k)
	      if(y1(p,k).lt.miny)miny=y1(p,k)
	      if(x1(p,k).gt.maxx)maxx=x1(p,k)
	      if(x1(p,k).lt.minx)minx=x1(p,k)
	      j=j+1
	  enddo
	enddo
c
c initialize plplot
	call plinit()
	call plssub(1,1)
       call plwid(1)
	call plcol0(15)   !color box and lables
	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(9)
	    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(1)
	    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	
	
20	call plend()	    	    
c	
       ans='C '
	dev='xwin'
       write(*,'(/1x,''|************* plot options menu ***************|'')')
       write(*,'(1x,''|-----------------------------------------------|'')')
       write(*,'(1x,''|       [s]ave   <[c]ontinue>   [r]eplot        |'')') 
       write(*,'(1x,''|_______________________________________________|'')')
       write(*,'(/1x,'' enter option number > '',$)')
       read(*,'(a1)')ans
       if((ans.eq.'S').or.(ans.eq.'s'))then
         dev='psc';ok=.false.;filename='fig1b.ps'
	  call plsetopt('geometry','600x1000')          !set default plot window dimension for printing only
	  call plsdev(dev)
         call plsfnam(filename)
         goto 10
       elseif((ans.eq.'R').or.(ans.eq.'r'))then
         ok=.true.
         goto 10
       elseif((ans.eq.'C').or.(ans.eq.'c').or.(ans.eq.' ').or.
     *                             (ans.eq.'Y').or.(ans.eq.'y'))then
         return
	endif
c
	return
	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=9000)
c     argument
      real*4 x1(mxy1,mxs1),x2(mxy1,mxs1),rline(mxy1)
      integer ny,ns,ify,mxy,mxs,idate(mxs,3)
      character tit*60,xlab*20,ylab*20,annot1*36,annot2*36
c     local
      integer red,green,blue
      real*4 x(mxlen),wrk(mxlen),miny,maxy,maxx,minx,range,miny1,maxy1,miny2,maxy2	
      integer p
c      
      character dev*80,filename*60,ans*2
      logical bg,ok
c
      mny=100000.0;mxy=-100000.0
      red=255;green=255;blue=255
      bg=.false.;ok=.true.;dev='xwin'
ccc      write(*,*)'from linguine2'
c
      minx=100000.0
      maxx=-100000.0
      miny1=100000.0
      maxy1=-100000.0
      do j=1,ns
        ify=idate(j,1)
        ily=idate(j,2)
        ny=ily-ify+1
        if(ify.lt.minx)minx=ify
        if(ily.gt.maxx)maxx=ily
        do i=1,ny
          datum=x1(i,j)
          if(datum.ne.-999.0)then
            if(datum.gt.maxy1)maxy1=datum
            if(datum.lt.miny1)miny1=datum
          endif
        enddo
      enddo
      miny2=100000.0
      maxy2=-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.maxy2)maxy2=datum
            if(datum.lt.miny2)miny2=datum
          endif
        enddo
      enddo
      miny=amin1(miny1,miny2)
      maxy=amax1(maxy1,maxy2)
ccc      write(*,'(1x,''miny1,maxy1,miny2,maxy2,miny,maxy: '',6f8.3)')miny1,maxy1,miny2,maxy2,miny,maxy
      range=maxy-miny
      maxy=maxy+range/10.
      miny=miny-range/10.
      if(miny.lt.0)miny=0.0
c      miny=0.0
c      
	call plsetopt('geometry','1000x600')          !set default plot window dimension
   10 if(ok)call plsdev('xwin')
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 plenv(minx,maxx,miny,maxy,0,0)
      call plfont(1)
      call pllab(xlab,ylab,' ')
      call plmtex('b',-35.5,.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',-33.75,0.05,0.0,annot1)
      call plcol0(1)
      call plmtex('b',-33.75,0.72,0.0,annot2)
c
c *** end plotting
c
      call plend()   
c  
c      ans='C '
c      dev='xwin'
c      write(*,'(/1x,''|************* plot options menu ***************|'')')
c      write(*,'(1x,''|-----------------------------------------------|'')')
c      write(*,'(1x,''|       [s]ave   <[c]ontinue>   [r]eplot        |'')') 
c      write(*,'(1x,''|_______________________________________________|'')')
c      write(*,'(/1x,'' enter option number > '',$)')
c      read(*,'(a1)')ans
c      if((ans.eq.'S').or.(ans.eq.'s'))then
c        dev='psc';ok=.false.;
c        filename=tit
c        call stringclean(filename,60)
c        do p=1,60
c          if(filename(p:p).eq.' ')goto 69
c        enddo
69      write(filename(p:p+2),'(a3)')'.ps'
c        call plsdev(dev)
c        call plsfnam(filename)
c        goto 10
c      elseif((ans.eq.'R').or.(ans.eq.'r'))then
c        ok=.true.
c        goto 10
c      elseif((ans.eq.'C').or.(ans.eq.'c').or.(ans.eq.' ').or.
c     *                             (ans.eq.'Y').or.(ans.eq.'y'))then
c        return
c      endif
c
      return
      end
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
