Script to calculate grids