Thermodynamics of granular materials