Algorithm for the rigorous coupled-wave analysis of grating diffraction | Synapse