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