Magnetic Structures and Phase Transitions in Thin and Ultrathin Films of Heavy Lanthanide Metals Investigated by Resonant Magnetic X-Ray Scattering