'Write variables in `mdict` to stream
Parameters
mdict : mapping
mapping with method ``items`` returns name, contents pairs where
``name`` which will appear in the matlab workspace in file load, and
``contents`` is something writeable to a matlab file, such as a numpy
array.
write_header : {None, True, False}, optional
If True, then write the matlab file header before writing the
variables.  If None (the default) then write the file header
if we are at position 0 in the stream.  By setting False
here, and setting the stream position to the end of the file,
you can append variables to a matlab file'

def put_variables(self, mdict, write_header=None):

    if (write_header is None):
        write_header = (self.file_stream.tell() == 0)
    if write_header:
        self.write_file_header()
    self._matrix_writer = VarWriter5(self)
    for (name, var) in mdict.items():
        if (name[0] == '_'):
            continue
        is_global = (name in self.global_vars)
        if self.do_compression:
            stream = BytesIO()
            self._matrix_writer.file_stream = stream
            self._matrix_writer.write_top(var, asbytes(name), is_global)
            out_str = zlib.compress(stream.getvalue())
            tag = np.empty((), NDT_TAG_FULL)
            tag['mdtype'] = miCOMPRESSED
            tag['byte_count'] = len(out_str)
            self.file_stream.write(tag.tostring())
            self.file_stream.write(out_str)
        else:
            self._matrix_writer.write_top(var, asbytes(name), is_global)
