def preprocess_scan(scan_file):
    """Preprocess the scan file to a form that chooch will accept."""
    try:
        with open(scan_file, 'r') as fh:
            i = int(fh.readlines()[1])
        return scan_file
    except Exception:
        data = open(scan_file, 'r').readlines()
        more_data = []
        for d in data:
            if not '#' in d and d.strip():
                more_data.append(d)
        data = more_data
        count = len(data)
        out = open('xia2-chooch.raw', 'w')
        out.write('Chooch Scan File from xia2\n%d\n' % count)
        for d in data:
            out.write('%f %f\n' % tuple(map(float, d.split(',')[:2])))
        out.close()
        return 'xia2-chooch.raw'
