import typing


def rinex_version(s: str) -> typing.Tuple[typing.Union[float, str], bool]:
    """

    Parameters
    ----------

    s : str
       first line of RINEX/CRINEX file

    Results
    -------

    version : float
        RINEX file version

    is_crinex : bool
        is it a Compressed RINEX CRINEX Hatanaka file
    """
    if not isinstance(s, str):
        raise TypeError('need first line of RINEX file as string')
    if len(s) < 2:
        raise ValueError(f'first line of file is corrupted {s}')

    if len(s) >= 80:
        if s[60:80] not in ('RINEX VERSION / TYPE', 'CRINEX VERS   / TYPE'):
            raise ValueError('The first line of the RINEX file header is corrupted.')

    # %% .sp3 file
    if s[0] == '#':
        if s[1] != 'c':
            raise ValueError('Georinex only handles version C of SP3 files.')
        return 'sp3' + s[1], False
    # %% typical RINEX files
    try:
        vers = float(s[:9])  # %9.2f
    except ValueError as err:
        raise ValueError(f'Could not determine file version from {s[:9]}   {err}')

    is_crinex = s[20:40] == 'COMPACT RINEX FORMAT'

    return vers, is_crinex