added grid calculate code.