optimized gridding in C