	real function quickpile(x,nvar,pctile,miss)
c	returns "pctile" percentile

	implicit none

	integer nvar,i
	real x(nvar),pctile,miss,rtile,frac
	integer iwk(nvar),nonmiss,whole
	integer malloc

	pointer (iptr, iwk)

	if(pctile.le.0.0.or.pctile.gt.100.0)then
	 quickpile=miss
	 return
	end if

c	Determine no. of non-missing values
	nonmiss=0
	do i=1,nvar
	 if(x(i).ne.miss)nonmiss=nonmiss+1
	end do
	if(nonmiss.eq.0)then
	 quickpile=miss
	 return
	end if

c	Rank
	iptr = malloc(nvar*4)
	call quickrank_miss(nvar,x,iwk,miss)

c	get percentile
	rtile=real(nonmiss)*pctile/100.0
	if(rtile.lt.1.0)rtile=1.0
	whole=int(rtile)
	frac=rtile-real(whole)
	i=nonmiss-whole+1
	quickpile=x(iwk(i))
	if(i.gt.1)then
	 quickpile=quickpile+frac*(x(iwk(i-1))-x(iwk(i)))
	end if

	call free(iptr)

	return
	end

