# Path: tecs/rinex/basic.py
# class NavigationMessage(Rinex):
#     """Base class for the navigation message.
#     """
# 
#     def __init__(self, f_obj, filename):
#         super(NavigationMessage, self).__init__(f_obj, filename)
# 
#     # FIXME join with ObservationData._parse_header
#     def _parse_header(self, header):
#         items = [self.ver_type]
# 
#         for line in header:
#             label = line[60:].rstrip()
#             for i in items:
#                 if i.label == label:
#                     i.value = line
#                     items.remove(i)
#                     break
# 
# def read_header(fobj):
#     """read_header(fobj) -> header
# 
#     Parameters
#     ----------
#     fobj : file-like object
# 
#     Returns
#     -------
#     header : list
#         header
# 
#     Notes
#     -----
#     Changes position in the file.
#     """
#     header = []
#     for line in fobj:
#         label = line[60:].rstrip()
#         if label == 'END OF HEADER':
#             break
#         header.append(line)
#     return header
# 
# class RinexError(Exception):
#     def __init__(self, fname, msg):
#         super(RinexError, self).__init__()
#         self.err_msg = "%s (%s)" % (msg, fname)
# 
#     def __str__(self):
#         return self.err_msg
# 
# Path: tecs/rinex/common.py
# def validate_epoch(epoch):
#     """validate_epoch(epoch) -> datetime
# 
#     do some checks:
# 
#     - sometimes the seconds or minutes value >= 60, to return datetime.datetime
#       we need to check this;
#     - converts YY to YYYY (datetime.datetime threats 92 and 1992 in different
#       ways.
# 
#     Parameters
#     ----------
#     epoch : list
#         epoch = [year, month, day, hour, min, sec, microsec]
# 
#     Returns
#     -------
#     datetime : datetime.datetime
#     """
#     epoch = epoch[:]
# 
#     # YY -> YYYY
#     if epoch[0] < 100:
#         if epoch[0] >= 89:
#             epoch[0] += 1900
#         elif epoch[0] < 89:
#             epoch[0] += 2000
# 
#     delta = datetime.timedelta(0)
# 
#     # epoch[-2] - seconds; epoch[-3] - minutes
#     # we do all calculation in seconds so we use multiplier
#     for i, ier in [(-2, 1), (-3, 60)]:
#         if 60 <= epoch[i] <= 120:
#             sec = (epoch[i] - 59) * ier
#             delta += datetime.timedelta(seconds=sec)
#             epoch[i] = 59
# 
#     epoch = datetime.datetime(*epoch) + delta
# 
#     return epoch
# 
# def sec2sec_ms(sec):
#     """sec2sec_ms(sec) -> sec, microsec
# 
#     Parameters
#     ----------
#     sec : float
# 
#     Returns
#     -------
#     seconds : int
#     microsec : int
#     """
#     microsec = (sec - int(sec)) * 1e+6
#     microsec = float("%.1f" % microsec)
# 
#     return int(sec), int(microsec)
# 
# Path: tecs/rinex/header.py
# class RinexVersionType(HeaderLabel):
#     def __init__(self, version):
#         super(RinexVersionType, self).__init__(version)
#         self.label = 'RINEX VERSION / TYPE'
# 
#     @property
#     def value(self):
#         # type: () -> tuple
#         return self._value
# 
#     @value.setter
#     def value(self, header_slice):
#         rinex_version = float(header_slice[:9])
#         file_type = header_slice[20]
#         satellite_system = header_slice[40]
# 
#         if self.version < 3:
#             if satellite_system == ' ':
#                 satellite_system = 'G'
# 
#         self._value = (rinex_version, file_type, satellite_system)
# 
# Path: tecs/rinex/nmsg.py
# class GPSNavigationMessage(GNSSNavigationMessage):
#     system = SAT_SYS_GPS
#     vals_per_orbit = (4, 4, 4, 4, 4, 4, 2)
# 
#     @property
#     def message(self):
#         return self._message
# 
#     @message.setter
#     def message(self, value):
#         self._message = value
# 
# class GLONASSNavigationMessage(GNSSNavigationMessage):
#     system = SAT_SYS_GLO
#     vals_per_orbit = (4, 4, 4)
# 
# class SBASNavigationMessage(GLONASSNavigationMessage):
#     system = SAT_SYS_GEO


from builtins import map
from tecs.rinex.basic import NavigationMessage, read_header, RinexError
from tecs.rinex.common import validate_epoch, sec2sec_ms
from tecs.rinex.header import RinexVersionType
from tecs.rinex.nmsg import GPSNavigationMessage, GLONASSNavigationMessage, \
    SBASNavigationMessage
import logging
        sec = epoch_record[17:22]

        sv_clock = [epoch_record[i:i + 19] for i in (22, 41, 60)]
        sv_clock = [i.lower().replace('d', 'e') for i in sv_clock]

        try:
            system = self.file_types[system]
            number = int(number)
            sec = sec2sec_ms(float(sec))
            epoch = list(map(int, epoch))
            epoch += list(sec)
            epoch = validate_epoch(epoch)
            sv_clock = list(map(float, sv_clock))
        except (ValueError, KeyError):
            msg = "Can't read epoch: {}.".format(epoch_record)
            raise RinexError(self.filename, msg)

        return system, number, epoch, tuple(sv_clock)

    def _next_rec(self, f_obj):
        pass


class Nav21(Nav2):
    _name = NAME + '.Nav21'
    version = 2.1
    systems = Nav2.systems + (SBASNavigationMessage,)
    file_types = {
        'N': GPSNavigationMessage.system,
        'G': GLONASSNavigationMessage.system,

# Path: tecs/rinex/basic.py
# class NavigationMessage(Rinex):
#     """Base class for the navigation message.
#     """
# 
#     def __init__(self, f_obj, filename):
#         super(NavigationMessage, self).__init__(f_obj, filename)
# 
#     # FIXME join with ObservationData._parse_header
#     def _parse_header(self, header):
#         items = [self.ver_type]
# 
#         for line in header:
#             label = line[60:].rstrip()
#             for i in items:
#                 if i.label == label:
#                     i.value = line
#                     items.remove(i)
#                     break
# 
# def read_header(fobj):
#     """read_header(fobj) -> header
# 
#     Parameters
#     ----------
#     fobj : file-like object
# 
#     Returns
#     -------
#     header : list
#         header
# 
#     Notes
#     -----
#     Changes position in the file.
#     """
#     header = []
#     for line in fobj:
#         label = line[60:].rstrip()
#         if label == 'END OF HEADER':
#             break
#         header.append(line)
#     return header
# 
# class RinexError(Exception):
#     def __init__(self, fname, msg):
#         super(RinexError, self).__init__()
#         self.err_msg = "%s (%s)" % (msg, fname)
# 
#     def __str__(self):
#         return self.err_msg
# 
# Path: tecs/rinex/common.py
# def validate_epoch(epoch):
#     """validate_epoch(epoch) -> datetime
# 
#     do some checks:
# 
#     - sometimes the seconds or minutes value >= 60, to return datetime.datetime
#       we need to check this;
#     - converts YY to YYYY (datetime.datetime threats 92 and 1992 in different
#       ways.
# 
#     Parameters
#     ----------
#     epoch : list
#         epoch = [year, month, day, hour, min, sec, microsec]
# 
#     Returns
#     -------
#     datetime : datetime.datetime
#     """
#     epoch = epoch[:]
# 
#     # YY -> YYYY
#     if epoch[0] < 100:
#         if epoch[0] >= 89:
#             epoch[0] += 1900
#         elif epoch[0] < 89:
#             epoch[0] += 2000
# 
#     delta = datetime.timedelta(0)
# 
#     # epoch[-2] - seconds; epoch[-3] - minutes
#     # we do all calculation in seconds so we use multiplier
#     for i, ier in [(-2, 1), (-3, 60)]:
#         if 60 <= epoch[i] <= 120:
#             sec = (epoch[i] - 59) * ier
#             delta += datetime.timedelta(seconds=sec)
#             epoch[i] = 59
# 
#     epoch = datetime.datetime(*epoch) + delta
# 
#     return epoch
# 
# def sec2sec_ms(sec):
#     """sec2sec_ms(sec) -> sec, microsec
# 
#     Parameters
#     ----------
#     sec : float
# 
#     Returns
#     -------
#     seconds : int
#     microsec : int
#     """
#     microsec = (sec - int(sec)) * 1e+6
#     microsec = float("%.1f" % microsec)
# 
#     return int(sec), int(microsec)
# 
# Path: tecs/rinex/header.py
# class RinexVersionType(HeaderLabel):
#     def __init__(self, version):
#         super(RinexVersionType, self).__init__(version)
#         self.label = 'RINEX VERSION / TYPE'
# 
#     @property
#     def value(self):
#         # type: () -> tuple
#         return self._value
# 
#     @value.setter
#     def value(self, header_slice):
#         rinex_version = float(header_slice[:9])
#         file_type = header_slice[20]
#         satellite_system = header_slice[40]
# 
#         if self.version < 3:
#             if satellite_system == ' ':
#                 satellite_system = 'G'
# 
#         self._value = (rinex_version, file_type, satellite_system)
# 
# Path: tecs/rinex/nmsg.py
# class GPSNavigationMessage(GNSSNavigationMessage):
#     system = SAT_SYS_GPS
#     vals_per_orbit = (4, 4, 4, 4, 4, 4, 2)
# 
#     @property
#     def message(self):
#         return self._message
# 
#     @message.setter
#     def message(self, value):
#         self._message = value
# 
# class GLONASSNavigationMessage(GNSSNavigationMessage):
#     system = SAT_SYS_GLO
#     vals_per_orbit = (4, 4, 4)
# 
# class SBASNavigationMessage(GLONASSNavigationMessage):
#     system = SAT_SYS_GEO


# Path: tecs/rinex/v2/n.py
from builtins import map
from tecs.rinex.basic import NavigationMessage, read_header, RinexError
from tecs.rinex.common import validate_epoch, sec2sec_ms
from tecs.rinex.header import RinexVersionType
from tecs.rinex.nmsg import GPSNavigationMessage, GLONASSNavigationMessage, \
    SBASNavigationMessage
import logging

        sec = epoch_record[17:22]

        sv_clock = [epoch_record[i:i + 19] for i in (22, 41, 60)]
        sv_clock = [i.lower().replace('d', 'e') for i in sv_clock]

        try:
            system = self.file_types[system]
            number = int(number)
            sec = sec2sec_ms(float(sec))
            epoch = list(map(int, epoch))
            epoch += list(sec)
            epoch = validate_epoch(epoch)
            sv_clock = list(map(float, sv_clock))
        except (ValueError, KeyError):
            msg = "Can't read epoch: {}.".format(epoch_record)
            raise RinexError(self.filename, msg)

        return system, number, epoch, tuple(sv_clock)

    def _next_rec(self, f_obj):
        pass


class Nav21(Nav2):
    _name = NAME + '.Nav21'
    version = 2.1
    systems = Nav2.systems + (SBASNavigationMessage,)
    file_types = {
        'N': GPSNavigationMessage.system,
        'G': GLONASSNavigationMessage.system,

        'H': SBASNavigationMessage.system