<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p><font face="Arial">Dear co-Scilabers,<br>
<br>
</font>In the help page of the write() function @ <a
class="moz-txt-link-freetext"
href="https://help.scilab.org/docs/6.1.1/en_US/write.html"
moz-do-not-send="true">https://help.scilab.org/docs/6.1.1/en_US/write.html</a>,
<br>
an enigmatic sentence somewhat describes a interesting writing
mode:<br>
"<br>
<i>Direct access files : x = write(file_desc, a, k, format). Here
k is the vector of records (one record</i><i><br>
</i><i> by row, i.e. m = prod(size(k))</i><i><br>
</i><br>
"<i>Direct access</i> can be very useful, in order to write only
targeted records, instead of the whole file.<br>
But here this description looks completely obscure to me, and
there is no related example.<br>
<br>
I have tried many things using such a syntax with a text file, for
instance with the following example, and all of them fail:</p>
<pre style="font-family:Monospaced;font-style:normal;font-size:14.0;"><span style="color:rgb(0,0,0);">a</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(50,185,185);">rand</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">5</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">3</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);">*</span><span style="color:rgb(188,143,143);">100</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">File</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">write_test.txt</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(174,92,176);text-decoration:underline;">mdelete</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">File</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">fm</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">(3(2x,f4.0))</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(0,0,0);">;</span> <span style="color:rgb(100,174,100);font-style:italic;">// 3*(2+4) = 18 bytes / row</span>
<span style="color:rgb(50,185,185);">write</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">File</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">a</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">fm</span><span style="color:rgb(74,85,219);">)</span>;
<span style="color:rgb(0,0,0);">fid</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(50,185,185);">file</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">open</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">File</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">unknown</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">direct</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">18</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">k</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(74,85,219);">[</span><span style="color:rgb(188,143,143);">3</span> <span style="color:rgb(188,143,143);">4</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">b</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(92,92,92);">-</span><span style="color:rgb(0,0,0);">a</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">k</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(255,170,0);">:</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(50,185,185);">write</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">fid</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">b</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">k</span><span style="color:rgb(0,0,0);">,</span> <span style="color:rgb(0,0,0);">fm</span><span style="color:rgb(74,85,219);">)</span>;
<span style="color:rgb(50,185,185);">file</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">close</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">fid</span><span style="color:rgb(74,85,219);">)
</span></pre>
<p> This yields an error:</p>
<p><font face="monospace">--> write(fid, b, k, fm)<br>
Incorrect file or format.<br>
</font><br>
</p>
<p>Would anyone have any hints about this syntax, noticeably about
the <i>k</i> and <i>m</i> meanings?<br>
<br>
Regards<br>
Samuel<br>
<br>
<br>
</p>
</body>
</html>