def ReadControls(filename):
    """read an image controls (.imctrl) file"""
    cntlList = ['wavelength', 'distance', 'tilt', 'invert_x', 'invert_y',
        'type', 'fullIntegrate', 'outChannels', 'outAzimuths', 'LRazimuth',
        'IOtth', 'azmthOff', 'DetDepth', 'calibskip', 'pixLimit', 'cutoff',
        'calibdmin', 'Flat Bkg', 'PolaVal', 'SampleAbs', 'dark image',
        'background image']
    File = open(filename, 'r')
    save = {}
    S = File.readline()
    while S:
        if S[0] == '#':
            S = File.readline()
            continue
        [key, val] = S.strip().split(':', 1)
        if key in ['type', 'calibrant', 'binType', 'SampleShape']:
            save[key] = val
        elif key in ['rotation']:
            save[key] = float(val)
        elif key in ['center']:
            if ',' in val:
                save[key] = eval(val)
            else:
                vals = val.strip('[] ').split()
                save[key] = [float(vals[0]), float(vals[1])]
        elif key in cntlList:
            save[key] = eval(val)
        S = File.readline()
    File.close()
    return save
