program WEIhds_
  !! Paul Sava (paul@sep.stanford.edu)
  !! 09/11/02
  !!
  !! Compute differential semblance 
  !! on migrated images in the offset domain
  !! (i.e. multiply by offset)
  !!
  !! input  mx-my-hx-hy-z
  !! output mx-my-hx-hy-z (multiplied by offset)

  use sep
  use myax_

  implicit none
  
  logical     :: verb
  type(paxis) :: az,ahx,ahy,amx,amy
  integer     :: iz,ihx,ihy,imx,imy
  complex, dimension(:,:,:,:), allocatable ::cdata

  real, dimension(:),   allocatable :: hx,hy
  real, dimension(:,:), allocatable :: hh

  call sep_init()

  call from_param("verb",verb,.false.)

  call pinaxis(amx,1)
  call pinaxis(amy,2)
  call pinaxis(ahx,3)
  call pinaxis(ahy,4)
  call pinaxis(az ,5)

  call sep_close()

  allocate(cdata(amx%n,amy%n,ahx%n,ahy%n))
  allocate(   hx(ahx%n),hy(ahy%n))
  allocate(   hh(ahx%n,ahy%n))

  ! compute offsets
  do ihy=1,ahy%n
     hy(ihy)=ahy%o + (ihy-1)*ahy%d
  end do
  do ihx=1,ahx%n
     hx(ihx)=ahx%o + (ihx-1)*ahx%d
  end do

  do ihy=1,ahy%n
     do ihx=1,ahx%n
        hh(ihx,ihy) = sqrt(hy(ihy)**2 + hx(ihx)**2)
     end do
  end do

  hh = hh / maxval(hh)

  ! apply multiplication
  do iz=1,az%n
     if(verb) write(0,*) iz,az%n
     call sep_read(cdata)

     do imy=1,amy%n
        do imx=1,amx%n
           cdata(imx,imy,:,:) = &
           cdata(imx,imy,:,:) * hh(:,:)
        end do
     end do

     call sep_write(cdata)
  end do


  deallocate(hx,hy,hh)
  deallocate(cdata)

  call exit(0)
end program WEIhds_






