Calculation of surface x-ray diffraction patterns in total external reflection conditions