module OW_shaper

 use OW_type
 use OW_parms

implicit none

contains

!===============================================
subroutine owshaper(source,GGS)
 integer			:: i,j,sign
 complex			:: source(:),GGS(:,:),temp(sou%w%n), temp1(sou%w%n), phase(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(i,max(1,j-10):min(j+10,sou%w%n))))/(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,:)=GGS(i,:)*abs(source)*abs(temp)/(abs(temp)**2+.1*maxval(abs(temp)))!*sign
   end if
end do

end subroutine
end module
