<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rt_location_log(logfile):
 """ Extract location information from a RefTek raw log-file. Function to read a specific RefTek RT130 log-file and find all location information. :type logfile: str :param logfile: The logfile to look in :returns: list of tuples of lat, lon, elevation in decimal degrees and km. :rtype: list """

    if os.name == 'nt':
        f = open(logfile, 'rb')
    else:
        f = open(logfile, 'rb')
    locations = []
    for line_binary in f:
        try:
            line = line_binary.decode("utf8", "ignore")
        except UnicodeDecodeError:
            warnings.warn('Cannot decode line, skipping')
            print(line_binary)
            continue
        match = re.search("GPS: POSITION:", line)
        if match:
            # Line is of form:
            # jjj:hh:mm:ss GPS: POSITION: xDD:MM:SS.SS xDDD:MM:SS.SS xMMMMMMM
            loc = line[match.end() + 1:].rstrip().split(' ')
            lat_sign = loc[0][0]
            lat = loc[0][1:].split(':')
            lat = int(lat[0]) + (int(lat[1]) / 60.0) + (float(lat[2]) / 3600.0)
            if lat_sign == 'S':
                lat *= -1
            lon_sign = loc[1][0]
            lon = loc[1][1:].split(':')
            lon = int(lon[0]) + (int(lon[1]) / 60.0) + (float(lon[2]) / 3600.0)
            if lon_sign == 'W':
                lon *= -1
            elev_sign = loc[2][0]
            elev_unit = loc[2][-1]
            if not elev_unit == 'M':
                raise NotImplementedError('Elevation is not in M: unit=' +
                                          elev_unit)
            elev = int(loc[2][1:-1])
            if elev_sign == '-':
                elev *= -1
            # Convert to km
            elev /= 1000
            locations.append((lat, lon, elev))
    f.close()
    return locations