  We discuss the LensClean algorithm which for a given gravitational lens model
fits a source brightness distribution to interferometric radio data in a
similar way as standard Clean does in the unlensed case. The lens model
parameters can then be varied in order to minimize the residuals and determine
the best model for the lens mass distribution. Our variant of this method is
improved in order to be useful and stable even for high dynamic range systems
with nearly degenerated lens model parameters. Our test case B0218+357 is
dominated by two bright images but the information needed to constrain the
unknown parameters is provided only by the relatively smooth and weak Einstein
ring. The new variant of LensClean is able to fit lens models even in this
difficult case. In order to allow the use of general mass models with
LensClean, we develop the new method LenTil which inverts the lens equation
much more reliably than any other method. This high reliability is essential
for the use as part of LensClean. Finally a new method is developed to produce
source plane maps of the unlensed source from the best LensClean brightness
models. This method is based on the new concept of dirty beams in the source
plane.
  The application to the lens B0218+357 leads to the first useful constraints
for the lens position and thus to a result for the Hubble constant. These
results are presented in an accompanying Paper II, together with a discussion
of classical lens modelling for this system.
