Updated define.gridcells() function

I modified the define.gridcells() function to properly handle
gridcells on the boundary of the study region.