Grid co-ordinates on an irregular surface

I think this post Reorganize point structure is very similar to your case. You just want to offset indexes so that they align with the correct row (right?)