module dimdrv2_
  !! Image perturbation derivative

  use utilities
  implicit none

  type(paxis) :: laz,lahx,lahy,lamx,lamy
  real, dimension(:), pointer, private :: zz
contains
  !----------------------------------------------------------------
  subroutine dimdrv2_init(az,ahx,ahy,amx,amy)
    type(paxis)       :: az,ahx,ahy,amx,amy
    integer           :: stat
    integer           :: m,i,iz

    laz=az
    lahx=ahx
    lahy=ahy
    lamx=amx
    lamy=amy

    allocate(zz(az%n), stat=stat)
    if(stat /=0) call seperr("cant allocate zz")
    do iz=1,az%n
       zz(iz) = az%o + (iz-1)*az%d
    end do
  end subroutine dimdrv2_init
  !----------------------------------------------------------------
  !! -i z R == dR/dkz
  !! in the x-domain
  subroutine dimdrv2(cdata)
    complex, dimension(:,:,:,:,:), pointer :: cdata
    integer :: imx,imy,ihx,ihy

    do ihx=1,lahx%n
       do ihy=1,lahy%n
          do imx=1,lamx%n
             do imy=1,lamy%n
                cdata(:,ihx,ihy,imx,imy) = &
                cdata(:,ihx,ihy,imx,imy) * (0,-1) * zz 
             end do
          end do
       end do
    end do

  end subroutine dimdrv2
  !----------------------------------------------------------------  
end module dimdrv2_

