Abstract
The paper describes an automatic inversion code to recover microstructured magnetic atmospheres (MISMAs) by fitting Stokes profiles. These solar model atmospheres incorporate small-scale fluctuations of the magnetic field vector, the velocity, the temperature, etc., which seems to be an intrinsic property of the magnetic photosphere. The model MISMAs considered for inversion have several distinct components. Each one of them is made of slender flux tubes, so that the whole vertical stratification of the MISMA is reconstructed from a finite set of parameters. The inversion code has been thoroughly tested using both synthetic and real observations. In particular, it successfully reproduces line profiles and model atmospheres corresponding to the quiet Sun and plage regions. As a by-product, we introduce a new error estimate for nonlinear least-squares minimizations.