module mask2i {
  use mask1
  use helicon
  use heliarr
  use cgstep_mod
  use reg_solver
contains
  subroutine maski (niter, dd, xx, known, aa1, aa2) {
    integer,                intent (in)  :: niter
    real,    dimension (:), intent (in)  :: dd
    type( filter),          intent (in)  :: aa1, aa2
    real,    dimension (:), intent (out) :: xx
    logical, dimension (:), pointer      :: known
    integer                              :: nx
    optional                             :: aa2
    call mask1_init (known); nx = size (dd)
    if (present (aa2)) {
       call heliarr_init (nx, aa1, aa2)
       call solver_reg (mask1_lop, cgstep, niter = niter, dat = dd, x = xx, 
                    reg = heliarr_lop, nreg = 2*nx, eps = 1.)
    } else {
       call helicon_init (aa1)
       call solver_reg (mask1_lop, cgstep, niter = niter, dat = dd, x = xx, 
                    reg = helicon_lop, nreg = nx, eps = 1.)
    }
    call cgstep_close ()
  }
}
