import csv


def extract_geo(csvfilename, sumlev):
    """Returns a dictionary of logrecno to FIPS codes for state, county, and tract"""
    
    output = {}
    
    geofile = open(csvfilename, 'r')
    geodata = csv.reader(geofile, quoting=csv.QUOTE_MINIMAL)
    
    for row in geodata:
        if row[2] == sumlev and row[3] == '00':
            logrecno = row[4]
            output[logrecno] = row[9]
            if sumlev in ['050','140']: output[logrecno] += row[10]
            if sumlev in ['140']: output[logrecno] += row[13]
    
    geofile.close()

    return output