<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( https://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2008 - INRIA
 * ...
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="mput">
    <refnamediv>
        <refname>mput</refname>
        <refpurpose>writes  byte or word in a given binary format</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>mput(x [, type, fd])</synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>x</term>
                <listitem>
                    <para>a vector of floating point or integer type numbers</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>fd</term>
                <listitem>
                    <para>
                        a scalar: a file descriptor returned by the function <function>mopen</function>. <literal>-1</literal>
                        stands for last opened file. Default value is
                        <literal>-1</literal>.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>type</term>
                <listitem>
                    <para>
                        a string: the binary format used to write all the entries of <varname>x</varname>.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            The <function>mput</function> function writes data to the output specified by the
            stream parameter <varname>fd</varname>. Data is written at the
            position at which the file pointer is currently pointing and
            advances the indicator appropriately.
        </para>
        <para>
            The <varname>type</varname> parameter is a conversion specifier which may be set to any of the
            following flag characters (with default value <literal>"l"</literal>):
        </para>
        <variablelist>
            <varlistentry>
                <term>"l", "i", "s", "ul", "ui", "us", "d", "f", "c", "uc"</term>
                <listitem>
                    <para>
                        for  writing respectively a long long, an int (long
                        int), a short, an unsigned long long int, an unsigned int (long int), an unsigned short, a double, a float, a char and an unsigned char. The bytes which are wrote are automatically swapped if necessary (by checking little-endian status) in order to produce machine independent binary files (in little-endian mode). This default swapping mode can be suppressed by adding a flag <code>swap = 0</code> in the <function>mopen</function> function.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>"..l" or "..b"</term>
                <listitem>
                    <para>
                        It is also possible to write in little-endian or big-endian
                        mode  by adding a <literal>"l"</literal> or
                        <literal>"b"</literal> character at the end of a
                        <varname>type</varname> specification. For example
                        <literal>"db"</literal> will write a double in big-endian mode.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
filen = 'test.bin';
mopen(filen,'wb');
mput(1996,'l');mput(1996,'i');mput(1996,'s');mput(98,'c');

// force little-endian
mput(1996,'ll');mput(1996,'il');mput(1996,'sl');mput(98,'cl');

// force big-endian
mput(1996,'lb');mput(1996,'ib');mput(1996,'sb');mput(98,'cb');

mclose();
mopen(filen,'rb');
if 1996<>mget(1,'l') then pause,end
if 1996<>mget(1,'i') then pause,end
if 1996<>mget(1,'s') then pause,end
if   98<>mget(1,'c') then pause,end

// force little-endian
if 1996<>mget(1,'ll') then pause,end
if 1996<>mget(1,'il') then pause,end
if 1996<>mget(1,'sl') then pause,end
if   98<>mget(1,'cl') then pause,end

// force big-endian
if 1996<>mget(1,'lb') then pause,end
if 1996<>mget(1,'ib') then pause,end
if 1996<>mget(1,'sb') then pause,end
if   98<>mget(1,'cb') then pause,end

mclose();
 ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="mclose">mclose</link>
            </member>
            <member>
                <link linkend="meof">meof</link>
            </member>
            <member>
                <link linkend="mfprintf">mfprintf</link>
            </member>
            <member>
                <link linkend="fprintfMat">fprintfMat</link>
            </member>
            <member>
                <link linkend="mfscanf">mfscanf</link>
            </member>
            <member>
                <link linkend="fscanfMat">fscanfMat</link>
            </member>
            <member>
                <link linkend="mget">mget</link>
            </member>
            <member>
                <link linkend="mgetl">mgetl</link>
            </member>
            <member>
                <link linkend="mgetstr">mgetstr</link>
            </member>
            <member>
                <link linkend="mopen">mopen</link>
            </member>
            <member>
                <link linkend="mprintf">mprintf</link>
            </member>
            <member>
                <link linkend="mputl">mputl</link>
            </member>
            <member>
                <link linkend="mputstr">mputstr</link>
            </member>
            <member>
                <link linkend="mseek">mseek</link>
            </member>
            <member>
                <link linkend="mtell">mtell</link>
            </member>
            <member>
                <link linkend="mdelete">mdelete</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
