Convex analysis and thermodynamics