A scheme for the numerical calculation of energy levels of rare-earth ions in a crystalline solid is presented. Stark fields of cubic, trigonal, tetragonal, orthorhombic and monoclinic symmetry are considered. As examples, optical luminescence spectra of erbium in the semiconductors zinc selenide and silicon are analysed. Based on the optical characterisation, the g tensors for Zeeman splitting in an applied magnetic field are predicted for the crystal-field ground states of these centres.