module OW_shaper

 use OW_type
 use OW_parms_areal

implicit none

contains

!===============================================
subroutine owshaper(source,GGS,sign)
 integer			:: i,j,sign
 complex			:: source(:),GGS(:,:),temp(sou%w%n)

temp=0
do i=padtraces+tapertr+1,kxm%n-(padtraces+tapertr)
   do j=1,sou%w%n
      temp(j)=temp(j)+sum(abs(GGS(max(1,j-10):min(j+10,sou%w%n),i)))/(min(j+10,sou%w%n)-max(1,j-10)+1)
   end do
end do
temp=temp/kxm%n
do i=padtraces+tapertr+1,kxm%n-(padtraces+tapertr)
   if (sum(abs(temp)**2+.1*maxval(abs(temp))) > 0) then
      GGS(:,i)=sign*GGS(:,i)*abs(source)*abs(temp)/(abs(temp)**2+.1*maxval(abs(temp)))
   end if
end do
end subroutine
end module
