subroutine eposcorr read x-ray and optical list call find_offset call correct_positions IF findrotation == TRUE THEN call find_all ! make a three dimensional search DO i=1, niter IF findrotation == TRUE THEN call find_rotation call find_offsets update the grid resolution ! for the last iteration a larger grid is used in order to get an error ! estimate END modify/write the x-ray list end subroutine eposcorr subroutine find_offset x_shift= y_shift =0 LOOP over x_offset grid elements LOOP over y_offset grid elements call subroutine likelihood store likelihood in array IF likelihood > best likelihood THEN update best likelihood, x_shift=x_offset , y_shift=y_offset END LOOP END LOOP xm = ym = 0 total_likelihood = 0 LOOP over likelihood array elements (= corresponding x_offset, y_offset) IF( distance( x/y_offset , x/y_shift ) < 0.5* grid size ) THEN xm = xm + likelihood * (x_offset - x_shift) ym = ym + likelihood * (y_offset - y_shift) total_likelihood = total_likelihood + likelihood END IF END LOOP ! New best offsets: x_shift = xm/total_likelihood y_shift = ym/total_likelihood end subroutine find_offset subroutine likelihood set likelihood = 0 set nmatches = 0 LOOP over elements X-ray list LOOP over elements optical list calculate the combined position error (sigma) calculate the distance (d) between the optical and X-ray source for given x and y offsets IF x-ray source within 5 sigma of optical source THEN nmatches = nmatches + 1 likelihood = likelihood + exp{ -0.5 * (d/sigma)^2 } END IF END LOOP END LOOP end subroutine likelihood