$totallayer2 required setting tag the layer number of the device. This layer number needs to be set in the beginning of input file. It is different from $totallayer, it is for the RCWA to use.
Example
$totallayer2 5