Method for calculating the electronic structure of correlated materials from a truly first-principles LDA+U scheme