An algorithm for calculating diffraction profiles of 2θ scans for multiple diffraction from crystals and thin films