1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2008 - INRIA
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * Copyright (C) 2021 - Samuel GOUGEON
9 * This file is hereby licensed under the terms of the GNU GPL v2.0,
10 * pursuant to article 5.3.4 of the CeCILL v.2.1.
11 * This file was originally licensed under the terms of the CeCILL v2.1,
12 * and continues to be available under such terms.
13 * For more information, see the COPYING file which you should have received
14 * along with this program.
17 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
18 xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
19 xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
20 xmlns:scilab="http://www.scilab.org" xml:id="mfprintf" xml:lang="ru">
22 <refname>mfprintf</refname>
23 <refpurpose>преобразует, форматирует и записывает данные в файл</refpurpose>
26 <title>Синтаксис</title>
27 <synopsis>mfprintf(fd, format, a1, ..., an)</synopsis>
30 <title>Аргументы</title>
36 скаляр, файловый дескриптор, предоставленный с помощью
37 <literal>mopen</literal> (это положительное число).
40 Если <varname>fd</varname> равен 0, то перенаправление в
41 стандартное устройство вывода сообщений об ошибках (stderr).
44 Если <varname>fd</varname> равен 6, то перенаправление в
45 стандартное устройство вывода (stdout).
48 УСТАРЕЛО: значение <literal>-1</literal> относится к файлу по
49 умолчанию (т. е. последнему открытому файлу).
57 a string providing the format to use to write all next arguments.
58 The <varname>format</varname> follows -- as close as possible -- the C printf
59 format operand syntax, as described in the
60 <link linkend="printf_conversion">printf_conversion</link> page.
61 UTF-8 extended characters are supported.
63 Numbered placeholders "%n$.." are not supported.
69 <term>a1, ..., an</term>
72 Data to be converted and written according to the <varname>format</varname>
73 argument. Supported types: all numbers, booleans, strings. Only the real part
74 of complex numbers is considered (current Scilab limitation).
81 <title>Описание</title>
83 <literal>mfprintf(fd, format, a1, a2, ..)</literal> replaces placeholders provided
84 in the <varname>format</varname> string with values of <varname>a1</varname>,
85 <varname>a2</varname>, .. converted according to each respective placeholder directive,
86 and writes the result to the file specified by its index <varname>fd</varname>.
89 If <varname>a1</varname>, <varname>a2</varname>, .. are arrays with multiple rows,
90 they feed the format row by row: the format is used iteratively for every row of the
91 (horizontally "concatenated") arrays, until the bottom
92 of the least tall array is reached. Remaining rows of taller arrays (if any) are ignored.
96 If the total number of columns of <varname>a1</varname>, <varname>a2</varname>, ..
97 is bigger than the number of placeholders in the <varname>format</varname>,
98 then extra columns are ignored. If it is smaller, an error is yielded.
101 Функция <literal>mfprintf</literal> является интерфейсом для версии функции <literal>fprintf</literal> на языке C.
105 <title>Примеры</title>
106 <programlisting role="example"><![CDATA[
107 fd = mopen(TMPDIR+'/text.txt','wt');
108 mfprintf(fd,'Привет, %s %d.\n','мир!',1);
109 mfprintf(fd,'Привет, %s %d.\n','Scilab',2);
110 mfprintf(fd,'Эта строка построена с помощью вектор-столбца (26:28) %d.\n',[26:28].');
111 mfprintf(fd,'Эта строка построена с помощью вектор-строки (26:28) %d.\n',[26:28]);
113 mfprintf(fd,'Эта строка построена с помощью матрицы %.3f.\n',A);
115 editor(TMPDIR+'/text.txt')
117 mfprintf(0,'stderr output.\n');
118 mfprintf(6,'stdout output.\n');
121 <programlisting role="example"><![CDATA[
123 A = [26.93 ; 63.25 ; 40.51 ; 91.84];
124 B = [ 3.62 ; 15.04 ; 25.3 ; 48.19];
129 Status = ["NOK" "NOK" "NOK" "OK"]';
130 Format = "Iteration %d: Results: A= %f B= %2d%% Status= %3s C(1)= %g C(2)= %e\n";
131 File = TMPDIR + "/mfprintf.txt";
132 fd = mopen(File, 'wt');
133 mfprintf(fd, Format, I, A, B, Status, C);
138 Iteration 1: Results: A= 26.930000 B= 3% Status= NOK C(1)= 4.37 C(2)= 2.806000e+01
139 Iteration 2: Results: A= 63.250000 B= 15% Status= NOK C(1)= 48.18 C(2)= Inf
140 Iteration 3: Results: A= 40.510000 B= 25% Status= NOK C(1)= 41.48 C(2)= Nan
141 Iteration 4: Results: A= 91.840000 B= 48% Status= OK C(1)= 26.39 C(2)= 7.783000e+01
145 Supernumerary columns or rows are ignored:
147 <programlisting role="example"><![CDATA[
148 A = [%T %F %T %T %F]';
152 File = TMPDIR + "/mfprintf.txt";
153 fd = mopen(File, 'wt');
154 mfprintf(fd, "OK? %s Value: %4.1f\n", A, B)
164 <refsection role="see also">
165 <title>Смотрите также</title>
166 <simplelist type="inline">
168 <link linkend="printf_conversion">printf_conversion</link>
171 <link linkend="csvWrite">csvWrite</link>
174 <link linkend="fprintfMat">fprintfMat</link>
177 <link linkend="write">write</link>
180 <link linkend="mputl">mputl</link>
183 <link linkend="mputstr">mputstr</link>
186 <link linkend="mopen">mopen</link>
189 <link linkend="mclose">mclose</link>
192 <link linkend="mprintf">msprintf</link>
195 <link linkend="mfscanf">mfscanf</link>
199 <refsection role="history">
200 <title>История</title>
203 <revnumber>6.1.1</revnumber>
205 Input data can be boolean.