  A big challenge in solar and stellar physics in the coming years will be to
decipher the magnetism of the solar outer atmosphere (chromosphere and corona)
along with its dynamic coupling with the magnetic fields of the underlying
photosphere. To this end, it is important to develop rigorous diagnostic tools
for the physical interpretation of spectropolarimetric observations in suitably
chosen spectral lines. Here we present a computer program for the synthesis and
inversion of Stokes profiles caused by the joint action of atomic level
polarization and the Hanle and Zeeman effects in some spectral lines of
diagnostic interest, such as those of the He I 10830 A and D_3 multiplets. It
is based on the quantum theory of spectral line polarization, which takes into
account all the relevant physical mechanisms and ingredients (optical pumping,
atomic level polarization, Zeeman, Paschen-Back and Hanle effects). The
influence of radiative transfer on the emergent spectral line radiation is
taken into account through a suitable slab model. The user can either calculate
the emergent intensity and polarization for any given magnetic field vector or
infer the dynamical and magnetic properties from the observed Stokes profiles
via an efficient inversion algorithm based on global optimization methods. The
reliability of the forward modeling and inversion code presented here is
demonstrated through several applications, which range from the inference of
the magnetic field vector in solar active regions to determining whether or not
it is canopy-like in quiet chromospheric regions. This user-friendly diagnostic
tool called "HAZEL" (from HAnle and ZEeman Light) is offered to the
astrophysical community, with the hope that it will facilitate new advances in
solar and stellar physics.
