module OW_wghtmute

use OW_type
use OW_parms_areal
use adj_mod
implicit none
real,private,allocatable			:: pick(:)

contains
!======================================================================
   subroutine wghtmute_lop_init(pick_in)
    real            :: pick_in(:)
    allocate(pick(img%xm%n))
    pick=pick_in
   end subroutine
!======================================================================
   function wghtmute_lop ( adj, add, modl, data) result(stat)
    integer            :: stat 
    logical,intent(in) :: adj,add 
    real,dimension(:)  :: modl,data 
    stat=1
    call adjnull( adj, add, modl, data)
    call wghtmute_lop2(adj,add,modl,data )
    stat=0
  end function 
!=======================================================
subroutine wghtmute_lop2(adj,add,modl,data )
logical                       :: adj,add 
real                          :: modl(img%xm%n,img%z%n),data(img%xm%n,img%z%n)
integer			:: j,k,i

if (adj) then
  do j=1,img%xm%n
     do k=1,img%z%n
        if (k < int(pick(j))) then
           modl(j,k)=0.
        else
           modl(j,k)=data(j,k)
        end if
     end do
  end do
else
  do j=1,img%xm%n
     do k=1,img%z%n
        if (k < int(pick(j))) then
           data(j,k)=0.
        else
           data(j,k)=modl(j,k)
        end if
     end do
  end do
end if
end subroutine
!=======================================================
subroutine wghtmute_lop3(adj,add,modl,data )
logical                       :: adj,add 
real                          :: modl(img%xm%n,img%sh%n,img%z%n),data(img%xm%n,img%sh%n,img%z%n)
integer			:: j,k,i

if (adj) then
  do j=1,img%xm%n
     do i=1,img%sh%n
        do k=1,img%z%n
           if (k < int(pick(j))) then
              modl(j,i,k)=0.
           else
              modl(j,i,k)=data(j,i,k)
           end if
        end do
     end do
  end do
else
  do j=1,img%xm%n
     do i=1,img%sh%n
        do k=1,img%z%n
           if (k < int(pick(j))) then
              data(j,i,k)=0.
           else
              data(j,i,k)=modl(j,i,k)
           end if
        end do
     end do
  end do
end if
end subroutine
!=========================
 subroutine wghtmute_close()
 if (allocated (pick)) deallocate(pick)
 end subroutine
!=========================
end module
