Added method writeGridToOutput