      subroutine hist_flat(h,n1,n2,nstep,flatness,hmin,nmin,hmax,nmax) 
c bb nov 1 2008. test_flat version of histogram flatness.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension h(n1:n2)
      nmin=n1
      hmin=h(n1)
      nmax=n1
      hmax=h(n1)
      do i=(n1+nstep),n2,nstep
        if(h(i).gt.half) then
          if(h(i).lt.hmin) then
            nmin=i
            hmin=h(i)
          endif
          if(h(i).gt.hmax) then
            nmax=i
            hmax=h(i)
          endif
        endif
      enddo
      flatness=hmin/hmax
      return
      end
