modified:   ScanPattern.R