A method for calculating the complex refractive index of inhomogeneous thin films