Inverse scattering for gratings and wave guides