      subroutine bootstrp(dat1,ndat,dat2,nbtr,qtl,nq) 
c bernd berg june 3 2005. 
c generates bootstrap sample of the mean and calculates some q-tiles.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension dat1(ndat), dat2(nbtr), qtl(nq) 
c
      do i=1,nbtr
      x=zero
        do j=1,ndat
          iran=1+int(ndat*rmafun())
          x=x+dat1(iran)
        end do
      dat2(i)=x/ndat
      end do       
c
      call heapsort(nbtr,dat2)
      n=nq/2
      do i=1,n
        ii=i+i-1
        call qtiles(nbtr,dat2,qtl(ii),xq1,xq2)
        qtl(ii)  =xq1
        qtl(ii+1)=xq2
      end do  
c
      return
      end
