def write(fn, s, overwrite=True):
    """General write function for surfaces

    Parameters
    ----------
    fn: str
        Surface filename. The extension determines how the file is written as
        follows. '.asc', FreeSurfer ASCII format; '.gii', GIFTI.
        Other formats are not supported.
    """
    if fn.endswith('.asc'):
        from mvpa2.support.nibabel import surf_fs_asc
        surf_fs_asc.write(fn, s, overwrite=overwrite)
    elif fn.endswith('.gii'):
        if not fn.endswith('.surf.gii'):
            raise ValueError('GIFTI output requires extension .surf.gii')
        from mvpa2.support.nibabel import surf_gifti
        surf_gifti.write(fn, s, overwrite=overwrite)
    else:
        raise ValueError('Not implemented (based on extension): %r' % fn)
