def txt2lon(lontxt):
    """txt2lat: input txt: N52'14'13.5 or N52"""
    try:
        lon = float(lontxt)
    except:
        txt = lontxt.upper().replace('E', '').replace('W', '-')
        neg = txt.count('-') > 0
        if txt.count("'") > 0 or txt.count('"') or txt.count(chr(176)) > 0:
            txt = txt.replace('"', "'").replace(chr(176), "'")
            degs = txt.split("'")
            div = 1
            lon = 0.0
            if neg:
                f = -1.0
            else:
                f = 1.0
            for xtxt in degs:
                if len(xtxt) > 0.0:
                    try:
                        lon = lon + f * abs(float(xtxt)) / float(div)
                    except:
                        print('txt2lon value error:', lontxt)
                        return 0.0
                div = div * 60
        else:
            try:
                neg = txt.count('-') > 0
                if neg:
                    f = -1.0
                else:
                    f = 1.0
                lon = f * abs(float(txt))
            except:
                print('txt2lon value error:', lontxt)
                return 0.0
    return lon
