ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
	subroutine rcurve(mxy,mxs,n,x,xrc,f,idate,pith,flag,mxage,eq,rcsjdt,ndt)
c compute a simple age aligned population mean curve
c argument decs
	integer mxy,mxs,n,mxage,rcsjdt,ndt
	real*4 flag,eq(7)
	integer pith(mxy),idate(mxs,3)
	real*4 x(mxy,mxs),xrc(mxy),f(mxy)
c locals decs
	integer mxd, p,j,k
	parameter (mxd=5000)    !must equal mxy
	real*4  num(mxd),sum(mxd)  
c	
	mxage=-9999
	do j=1,mxd
	  sum(j)=0.0;num(j)=0.0
	enddo
	do j=1,n
	  p=pith(j)
	  do k=1,idate(j,3)
	     sum(p)=sum(p)+x(k,j)
	     num(p)=num(p)+1.
	     p=p+1
	  enddo
	  if(idate(j,3).gt.mxage)mxage=idate(j,3)
	enddo
c	
	do p=1,mxage
	  if(num(p).ne.0)then
	    xrc(p)=sum(p)/num(p)
	  else
	    xrc(p)=flag
	  endif
c	  write(*,*)p,xrc(p)
	enddo
c
       call detrend2(xrc,f,mxage,mxage,eq,rcsjdt,mxy,ndt)			!Hakan

	return
	end
	
