module bin1  
! Data-push binning in 1-D.
  use adj_mod
  implicit none
  integer, private :: m1 
  real, private :: o1 
  real, private :: d1 
  real ,private,  dimension (:), pointer  :: coord 
  contains
  subroutine bin1_init ( m1_in,o1_in,d1_in,coord_in )
    integer    :: m1_in 
    real    :: o1_in 
    real    :: d1_in 
    real ,   dimension (:), pointer :: coord_in 
    m1 = m1_in 
    o1 = o1_in 
    d1 = d1_in 
    coord => coord_in
  end subroutine
  function bin1_lop ( adj, add, mm, dd) result(stat)
    integer            :: stat 
    logical,intent(in) :: adj,add 
    real,dimension(:)  :: mm,dd 
    call adjnull (adj,add,mm,dd )
    call bin1_lop2(adj,add,mm,dd )
    stat=0
  end function 
  subroutine bin1_lop2(adj,add,mm,dd)
    logical,intent(in) :: adj,add 
    real, dimension (m1)  :: mm 
    real, dimension (:)  :: dd 
    integer    i1, id
    do id=1,size(dd)
      i1 = 1.5 + (coord(id)-o1)/d1
      if ( 1<=i1 .and. i1<=m1 ) then
        if ( adj) then
          mm(i1) = mm(i1) + dd(id)
        else
          dd(id) = dd(id) + mm(i1)
        end if
      end if
    end do
  end subroutine 
  subroutine bin1_close()
  end subroutine 
end module 
