  The rigorous coupled-wave analysis (RCWA) is one of the most successful and
widely used methods for modeling periodic optical structures. It yields fast
convergence of the electromagnetic far-field and has been adapted to model
various optical devices and wave configurations. In this article, we
investigate the accuracy with which the electromagnetic near-field can be
calculated by using RCWA and explain the observed slow convergence and
numerical artifacts from which it suffers, namely unphysical oscillations at
material boundaries due to the Gibb's phenomenon. In order to alleviate these
shortcomings, we also introduce a mathematical formulation for accurate
near-field calculation in RCWA, for one- and two-dimensional straight and
slanted diffraction gratings. This accurate near-field computational approach
is tested and evaluated for several representative test-structures and
configurations in order to illustrate the advantages provided by the proposed
modified formulation of the RCWA.
