Maybe I missed the multiplication by two for the two possible incrementations, so maybe it should be:
s = (ny*nx + nx*nz + nx*nz - 2) * 18
The issue is a typo, which is not surprising with those crazy numbers I got. Above is wrong, below is correct and is working in my tests.
s = (ny*nx + nx*nz + ny*nz - 2) * 18
Stephen Skory email@example.com http://stephenskory.com/ 510.621.3687 (google voice)