<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 11/26/2013 07:13 PM, Eduardo
Torrecillas wrote:<br>
</div>
<blockquote
cite="mid:CADqPe=tXh0xrH4CYqKQ8ydVXd9YJ4fR6DWccfDKjqaMYN-EZog@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>Hello all,<br>
<br>
</div>
I currently have some text files and I would like
to extract information from them using Scilab.<br>
I have done this before, using mopen and mgetl,
for example.<br>
<br>
</div>
Don't know why, but strangely in this case it is not
working. I am using Scilab 5.4.1 on Ubuntu (but
Scilab 5.4.0 under Windows produced the same
result).<br>
<br>
</div>
Please check the attached text file.<br>
<br>
</div>
Simple code such as:<br>
<br>
fd=mopen('scilab_example.txt','r')<br>
</div>
phrase=mgetl(fd,1)<br>
<br>
</div>
Produces:<br>
<br>
</div>
phrase=ÿp<br>
<br>
</div>
If i still try to use mgetl, next lines are always returned as
empty.<br>
<br>
Does anybody have any clue on whats happening?<br>
<br>
Best regards,<br clear="all">
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div><br>
-- <br>
Eduardo Torrecillas<br>
AER-09
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<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>
<br>
Hi,<br>
<br>
Here is what I found:<br>
<br>
On my linux box, it seems your file is UTF-16:<br>
<br>
$ file scilab_example.txt <br>
scilab_example.txt: Little-endian UTF-16 Unicode text, with CRLF, CR
line terminators<br>
<br>
I cannot read it with mgetl, but I can use mgetstr:<br>
<br>
-->fd=mopen('scilab_example.txt','r')<br>
fd =<br>
<br>
1. <br>
<br>
-->chars=mgetstr(50)<br>
chars =<br>
<br>
�� 6 0 A 4 8 8 F / 1 <br>
<br>
-->chars=mgetstr(50)<br>
chars =<br>
<br>
9 - 1 9 - 2 1 4 8 8 * / 1 9 - 1 9 - 2 1 4 8 <br>
<br>
-->chars=mgetstr(50)<br>
chars =<br>
<br>
8 * / 1 9 - 1 9 - 2 1 4 8 8 * / 1 9 - 1 9 - 2 <br>
<br>
<br>
As you can see, it looks like a problem of encoding (the �� or the
ÿp are usually showing up when encoding is wrong). <br>
You can solve it that way:<br>
<br>
$ iconv -f UTF-16 -t LATIN1 scilab_example.txt > latin1.txt<br>
<br>
than in Scilab:<br>
<br>
-->fd=mopen('latin1.txt','r')<br>
fd =<br>
<br>
1. <br>
<br>
-->phrase=mgetl(fd,1)<br>
phrase =<br>
<br>
60A 488F/19-19-21 488*/19-19-21 488*/19-19-21
488*/19-19-21 <br>
<br>
Hope it helps<br>
<br>
<br>
<br>
</body>
</html>