module base_mskopr_mod
  implicit none

  real, dimension(:), pointer, private :: mask

contains

  integer function base_mskopr_init(mask_in) result(stat)
    real, dimension(:), target :: mask_in
    mask => mask_in
    stat = 0 
  end function

  integer function base_mskopr_oper(adj, add, modl, data) result(stat)
    logical            :: adj, add
    real, dimension(:) :: modl
    real, dimension(:) :: data

    if (.not.add) then
       if (adj) then
          modl = 0.
       else
          data = 0.
       end if 
    end if

    if (adj) then
        modl = modl + mask * data
    else
        data = data + mask * modl
    end if
    stat = 0
  end function

  integer function base_mskopr_clos() result(stat)
    nullify(mask)
    stat = 0
  end function
end module
