module hes_locprd_mod
  implicit none
  real   , dimension(:), pointer, private :: rhes
  complex, dimension(:), pointer, private :: ches
  integer                                 :: ndim

contains

  integer function hes_rlocpd_init(rhes_in, ndim_in) result(stat)
  end function

  integer function hes_clocpd_init(ches_in, ndim_in) result(stat)
    complex, dimension(ndim_in), target :: ches_in
    integer                             :: ndim_in

    ches => ches_in
    ndim =  ndim_in

    stat =  0
  end function


  integer function hes_clocpd_oper(adj, add, lmod, ldat) result(stat)
    logical                  :: adj
    logical                  :: add
    complex, dimension(ndim) :: lmod
    complex, dimension(ndim) :: ldat

    if (.not.add) then
       if (adj) then
          lmod = 0.
       else
          ldat = 0.
       end if
    end if

    if (adj) then
       lmod = lmod + ldat * cabs(lhes)
    else
       ldat = ldat + lmod * cabs(lhes)
    end if

    stat = 0

  end function


  integer function hes_clocpd_clos() result(stat)
    nullify(lhes)
    ndim = 0
    stat = 0
  end function

end module
