module weiop_tmp
  !! compute CIGs
  !!        offset domain (weihcig)
  !! ray parameter domain (weipcig)

  use wei_util
  use wei_pro
  use wei_par
  !---------------
  implicit none

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

contains
  !----------------------------------------------------------------  
  !! h-domain CIG
  integer function weiop_dcig_init() result(st)
    integer :: ihx,ihy
    character(len=128), parameter :: unit='weiop_dcig_init'
#ifdef DEBUG
    if(wpro%dbg>0) call in(unit)
#endif

    call weimem_add(4,wpro%ahx%n,unit)
    allocate(hx(      wpro%ahx%n))

    call weimem_add(4,wpro%ahy%n,unit)
    allocate(hy(      wpro%ahy%n))

    call weimem_add(4,wpro%ahx%n*wpro%ahy%n,unit)
    allocate(hh(      wpro%ahx%n,wpro%ahy%n))

    do ihy=1,wpro%ahy%n
       hy(ihy)=wpro%ahy%o + (ihy-1)*wpro%ahy%d
    end do

    do ihx=1,wpro%ahx%n
       hx(ihx)=wpro%ahx%o + (ihx-1)*wpro%ahx%d
    end do

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

    hh = hh / maxval(hh)

    call weimem_cut(4,wpro%ahx%n,unit)
    deallocate(hx)
    call weimem_cut(4,wpro%ahy%n,unit)
    deallocate(hy)
#ifdef DEBUG
    if(wpro%dbg>0) call out(unit)
#endif
    st=weiOK
  end function weiop_dcig_init
  !----------------------------------------------------------------
  integer function weiop_dcig(wfld,iws,ith) result(st)
    complex, dimension(:,:,:,:,:), pointer :: wfld
    integer, intent(in) :: iws,ith
    integer             :: imx,imy
    integer             :: ihx,ihy
    character(len=128), parameter :: unit='weiop_dcig'
#ifdef DEBUG
    if(wpro%dbg>9) call in(unit)
#endif

    do imy=1,wpro%amy%n
       do imx=1,wpro%amx%n
          do ihy=1,wpro%ahy%n
             do ihx=1,wpro%ahx%n
                wfld(imx,imy,ihx,ihy,ith) = &
                wfld(imx,imy,ihx,ihy,ith) * hh(ihx,ihy)
             end do
          end do
       end do
    end do

#ifdef DEBUG
    if(wpro%dbg>9) call out(unit)
#endif
    st=weiOK
  end function weiop_dcig
  !----------------------------------------------------------------  
  !----------------------------------------------------------------  
end module weiop_tmp










