Constrained variable clustering and the best basis problem in functional data analysis