Provide code to extract the top surface from a three-dimensional grid