	subroutine slpt(mxy,mxs,x,idate,nc)
c performs adaptive power transformation on matrix x alla cook and peters 1997, holocene
c pjk 2011, SU
c argument decs
	integer mxy,mxs,nc
	real*4 x(mxy,mxs)
	integer idate(mxs,3)
	
c local declarations
	integer p,k
	real*4 mr(5000),sr(5000) !dimension must equal mxy
	real*4 sl,yi
c	
	do k=1,nc
	       n=(idate(k,2)-idate(k,1))+1
		do p=2,n
	  		mr(p-1)=log((x(p,k)-x(p-1,k))/2.)
	  		sr(p-1)=log(abs(x(p,k)-x(p-1,k))
		enddo
		call tren2(n-1,mr,sr,sl,yi)
		pt=1-sl
		do p=1,n
	   		x(p,k)=x(p,k)**pt
		enddo
	return
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
*rtn trend2: fits linear regression line to data pairs
*
* programmed (c) may 1987 from trend by
* richard l holmes, holzbiologie - bfh, universitaet hamburg - germany
* modified (c) 04 aug 1990
*
*  n:  number of values in each array
*  x:  array of horizontal coordinates
*  y:  array of vertical coordinates
*  sl: slope of regression
*  yi: y-axis intercept
*
*  equation:  y = sl * x + yi
*
      subroutine trend2(n,x,y,sl,yi)
      real x(1),y(1)
      an=float(n)
      t=0.
      w=0.
      v=0.
      z=0.
      do 10 i=1,n
      z=z+x(i)
      t=t+x(i)*x(i)
      v=v+y(i)*x(i)
   10 w=w+y(i)
      ymean=w/an
      if((t-z*z/an) .ne. 0.)then
      sl=(v-w*z/an)/(t-z*z/an)
      else
      sl=0.
      endif
      yi=ymean-sl*z/an
      end ! trend2
