This code is forked from Dr Amin Khavasi's personal page ("http://ee.sharif.ir/~khavasi/index_files/Page1077.htm"), and it is recommended to acknowledge Dr Amin Khavasi and cite the article below:
Amin Khavasi, Ali Kazemi Jahromi, and Khashayar Mehrany. "Longitudinal Legendre polynomial expansion of electromagnetic fields for analysis of arbitrary-shaped gratings", J. Opt. Soc. Am. A 25(7):1564- 1573.
A comparison of C method, DM, RCWA and LPEM can found in the document.