<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body>
<p>Hello David,</p>
<p><br>
</p>
<p>Thanks.<br>
No I did not have a look at fscanfMat, as I had in mind to also
import the header and footer.</p>
<p>Samuel and Jan also proposed to simply use "mgetl(fd)" to grab
the whole file at once.<br>
Their solution seems to work (or at least does not crash scilab on
the first file I tested!).</p>
<p><br>
</p>
<p>Thank you all for your kind help,</p>
<p><br>
</p>
<p>Antoine<br>
</p>
<p><br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 27/04/2020 18:06, CHEZE David 227480
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:C1165F01A4B61C48AF8B97D1C4AB348B918E8389@EXDAG0-B2.intra.cea.fr">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<style id="owaParaStyle">P {
MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
</style>
<div style="color: rgb(0, 0, 0); font-family: Tahoma; font-size:
10pt; direction: ltr;">
<p>Hi Antoine,</p>
<p> </p>
<p>did you also look at fscanfMat ? It's handy when space or
tab separators.</p>
<p> </p>
<p>regards,</p>
<p> </p>
<p>David</p>
<hr tabindex="-1">
<div id="divRpF743245" style="direction: ltr;"><font size="2"
face="Tahoma" color="#000000"><b>De :</b> users
[<a class="moz-txt-link-abbreviated" href="mailto:users-bounces@lists.scilab.org">users-bounces@lists.scilab.org</a>] de la part de Antoine
Monmayrant [<a class="moz-txt-link-abbreviated" href="mailto:antoine.monmayrant@laas.fr">antoine.monmayrant@laas.fr</a>]<br>
<b>Envoyé :</b> lundi 27 avril 2020 17:40<br>
<b>À :</b> Users mailing list for Scilab<br>
<b>Objet :</b> [Scilab-users] parsing TSV (or CSV) file with
scilab is a nightmare<br>
</font><br>
</div>
<div>
<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"
target="_blank" 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"
target="_blank" 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"
target="_blank" moz-do-not-send="true">http://bugzilla.scilab.org/show_bug.cgi?id=16419</a><br>
</p>
</div>
</div>
<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>