<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Antoine</p>
<p>To find out how long the file is (although not strictly
necessary) I normally use:</p>
<pre style="font-family:Monospaced;font-style:normal;font-size:12.0;"><span style="color:rgb(0,0,0);">fid</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(50,185,185);">mopen</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">datafile</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">rb</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(50,185,185);">mseek</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">0</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">fid</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">end</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">lef</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">mtell</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">fid</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(50,185,185);">mseek</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">0</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><span style="color:rgb(0,0,0);">;
Then you can read in the whole file byte by byte (or split it up if it is big) :
</span><span style="color:rgb(0,0,0);">data</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(0,0,0);">mgeti</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">lef</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">'</span><span style="color:rgb(188,143,143);">c</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>
<span style="color:rgb(0,0,0);"></span></pre>
<p>The rest is just looking for the different letters and sort based
on that. <br>
</p>
<p>Jan<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 2020-04-27 17:40 PM, Antoine
Monmayrant wrote:<br>
</div>
<blockquote type="cite"
cite="mid:b466b4ea-b1c8-1309-9e89-f77eb4d01274@laas.fr">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<p>Hi all,</p>
<p><br>
</p>
<p>This is both a rant and desperate cry for help.<br>
I'm trying to parse some TSV data (tab separated data file) with
scilab and I cannot find a way to navigate around the minefield
of bugs present in meof/mgetl/mgetstr/csvRead.</p>
<p>A bit of context: I need to load into scilab data generated by
a closed source software.<br>
The data is in the form of many TSV files (that I cannot share
in full, just some redacted bits) with a header and a footer.<br>
I don't want to hand modify these files or edit them in any way
(I need to keep this as portable as possible, so no
sed/awk/grep...)<br>
</p>
<h2>OPTION 1: csvRead</h2>
<p>That's the most intuitive solution, however, because of <a
class="moz-txt-link-freetext"
href="http://bugzilla.scilab.org/show_bug.cgi?id=16391"
moz-do-not-send="true">http://bugzilla.scilab.org/show_bug.cgi?id=16391</a>
and the presence of more than 1 empty line in my header/footer,
this crashes Scilab.</p>
<h2>OPTION 2: hand parsing line by line using mgetl/meof<br>
</h2>
<p>I tried:</p>
<p>filename="tsv.txt";<br>
[fd, err] = mopen(filename, 'rt');<br>
while ~meof(fd) do<br>
   txtline=mgetl(fd,1);<br>
end<br>
mclose(fd)<br>
</p>
<p>Saddly, and contrary to what's written in "help mgetl", meof
keeps on returning 0, well passed the end of the file and the
while never ends!</p>
<h2>OPTION 3: hand parsing chunk by chunk using mgetstr/meof</h2>
<p>"help meof" does not confirm that meof should work with mgetl,
but mgetstr is specifically listed.<br>
I thus tried:</p>
<p>filename="tsv.txt";<br>
[fd, err] = mopen(filename, 'rt');<br>
while ~meof(fd) do<br>
   txtchunk=mgetstr(80,fd);<br>
end<br>
mclose(fd)</p>
<p>But thanks to <a class="moz-txt-link-freetext"
href="http://bugzilla.scilab.org/show_bug.cgi?id=16419"
moz-do-not-send="true">http://bugzilla.scilab.org/show_bug.cgi?id=16419</a>
this is also crashing Scilab.</p>
<p><br>
</p>
<h2>OPTION 4: Can anyone here help me with this?</h2>
<p> I am really running out of ideas.<br>
Did I miss some -hmm- obvious combination of available file
parsing scilab functions to achieve my goal?<br>
I have the feeling that it would have been faster for me to just
learn a totally new language that does not suck at parsing files
than trying to get it to work with scilab....</p>
<p><br>
</p>
<p>Antoine</p>
<p>(depressed)<br>
</p>
<p><br>
</p>
<p><br>
</p>
<p><a class="moz-txt-link-freetext"
href="http://bugzilla.scilab.org/show_bug.cgi?id=16419"
moz-do-not-send="true">http://bugzilla.scilab.org/show_bug.cgi?id=16419</a><br>
</p>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
</blockquote>
</body>
</html>