      subroutine bining(ndat,data,nbins,datb) ! bernd berg, jan 14 1992.
c
c    purpose:                                                         
c    calculation of  nbins  binned data from  ndat   original data.
c                                                                     
c    input:  (unchanged on exit)
c    ndat:    number of original data.
c    data:    array vector containing the original data.
c    nbins:   number of bins requested.
c                                                                     
c    output:
c    datb:    array containing the binned data.
c
      include '../../libs/fortran/implicit.sta' 
      include '../../libs/fortran/constants.par' 
      dimension data(ndat),datb(nbins)
      data iwarn /0/
c
      nbin=ndat/nbins
      ntest=nbin*nbins
      if(iwarn.eq.0 .and. ntest.ne.ndat) then
        print*,'warning from subroutine bining:'
        print*,'ndat =      ',ndat
        print*,'nbin*nbins =',ntest
        print*,'nbin,nbins: ',nbin,nbins
        iwarn=iwarn+1
        print*,'no warnings in future calls!'
      end if
c
      do i=1,nbins
        datb(i)=zero
        do j=1,nbin
          jj=j+(i-1)*nbin
          datb(i)=datb(i)+data(jj)
        end do 
        datb(i)=datb(i)/nbin
      end do    
c
      return
      end
