fix bug in coords2grid