def save_block_to_crt(filename, group, norrec='all', store_errors=False):
    """Save a dataset to a CRTomo-compatible .crt file

    Parameters
    ----------
    filename : string
        Output filename
    group : pandas.group
        Data group
    norrec : string
        Which data to export Possible values: all|nor|rec
    store_errors : bool
        If true, store errors of the data in a separate column

    """
    if norrec != 'all':
        group = group.query('norrec == "{0}"'.format(norrec))

    # todo: we need to fix the global naming scheme for columns!
    with open(filename, 'wb') as fid:
        fid.write(
            bytes('{0}\n'.format(len(group)), 'UTF-8')
        )

        AB = group['a'] * 1e4 + group['b']
        MN = group['m'] * 1e4 + group['n']
        line = [
            AB.values.astype(int),
            MN.values.astype(int),
            group['r'].values,
        ]

        if 'rpha' in group:
            line.append(group['rpha'].values)
        else:
            line.append(group['r'].values * 0.0)

        fmt = '%i %i %f %f'
        if store_errors:
            line += (
                group['d|Z|_[Ohm]'].values,
                group['dphi_[mrad]'].values,
            )
            fmt += ' %f %f'

        subdata = np.array(line).T
        np.savetxt(fid, subdata, fmt=fmt)
Save a dataset to a CRTomo-compatible .crt file

    Parameters
    ----------
    filename : string
        Output filename
    group : pandas.group
        Data group
    norrec : string
        Which data to export Possible values: all|nor|rec
    store_errors : bool
        If true, store errors of the data in a separate column