Depth dependent local structures in thin films unraveled by grazing incidence x-ray absorption spectroscopy