module grad2fill  
! min r(m) = L J m + L known  where L is a lowcut filter.
  use igrad2
  use cgstep_mod
  use mask1
  use solver_smp_mod
  implicit none
  contains
  subroutine grad2fill2( niter, m1, m2, mm, mfixed)
    integer,                    intent (in)     :: niter, m1,m2
    logical, dimension (m1*m2), intent (in)     :: mfixed      
    ! mask for known
    real,    dimension (m1*m2), intent (in out) :: mm          
    ! model
    real,    dimension (m1*m2*2)                :: yy          
    ! lowcut output
    logical, dimension (:),     pointer         :: msk
    allocate(msk(size(mfixed)))
    msk=.not.mfixed
    call mask1_init(msk)
    call igrad2_init(m1,m2)
    yy = 0.     ! initialize
    call solver_smp(m=mm, d=yy, Fop=igrad2_lop, stepper=cgstep, niter=niter&
      &, m0=mm, Jop=mask1_lop)
    call cgstep_close ()
  end subroutine 
end module 
