We describe a new LTE inversion code for the analysis of Stokes profiles em
erging from unresolved magnetic elements. It has been specifically designed
to obtain the thermal, dynamic, and magnetic properties of these structure
s in a self-consistent manner by fitting the whole shape of the observed sp
ectra. The inversion code is based on a previous scheme by Ruiz Cobo & del
Toro Iniesta and implements the thin flux-tube model as a reasonable descri
ption of reality. All physical parameters considered relevant for the probl
em (including velocity fields) are retrieved by means of a. Marquardt nonli
near least-squares algorithm. We present the results of extensive tests aim
ed at characterizing the behavior of the code so as to understand its limit
ations for the analysis of real observations. The code is found to produce
accurate results even with only two spectral lines and noisy Stokes I and V
profiles. A detailed error treatment, in which the covariances between par
ameters are explicitly included, is also carried out in order to investigat
e the uniqueness and reliability of the inferred model atmospheres.