On the determination of accurate intensities from powder diffraction data. I: Whole-pattern fitting with a least-squares procedure