The work function is the minimum thermodynamic work needed to remove an electron from a solid (or surface) to a point in the vacuum. The work function is not a characteristic of a bulk material, but rather a property of the surface of the material.
The work function W for a given surface is defined by the difference between Fermi level and electrostatic potential in the vacuum:
$W = -e\phi - E_f$
where $\phi$ is the electrostatic potential in the vacuum and $E_f$ is the Fermi level of the surface.
One can use Cubecruncher to compute the profile along the normal of the surface to obtained the electrostatic potential of the given surface and vacuum.
cubecruncher.x -i input.cube -o output.cube -1d_profile 3 0.001