[Scilab-users] Help with text files

classic Classic list List threaded Threaded
7 messages Options
Eduardo Torrecillas Eduardo Torrecillas
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Help with text files

Hello all,

I currently have some text files and I would like to extract information from them using Scilab.
I have done this before, using mopen and mgetl, for example.

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).

Please check the attached text file.

Simple code such as:

fd=mopen('scilab_example.txt','r')
phrase=mgetl(fd,1)

Produces:

phrase=ÿp

If i still try to use mgetl, next lines are always returned as empty.

Does anybody have any clue on whats happening?

Best regards,

--
Eduardo Torrecillas
AER-09

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

scilab_example.txt (9K) Download Attachment
paul.carrico paul.carrico
Reply | Threaded
Open this post in threaded view
|

Re: Help with text files

Try basicaly …

phrase=mgetl(fd)

then you’ve an array of characters …

 

Paul

 

 

 

De : users [mailto:[hidden email]] De la part de Eduardo Torrecillas
Envoyé : mardi 26 novembre 2013 19:14
À : International users mailing list for Scilab.
Objet : [Scilab-users] Help with text files

 

Hello all,

I currently have some text files and I would like to extract information from them using Scilab.
I have done this before, using mopen and mgetl, for example.

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).

Please check the attached text file.

Simple code such as:

fd=mopen('scilab_example.txt','r')

phrase=mgetl(fd,1)

Produces:

phrase=ÿp

If i still try to use mgetl, next lines are always returned as empty.

Does anybody have any clue on whats happening?

Best regards,


--
Eduardo Torrecillas
AER-09




Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection Antivirus avast! est active.



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Eduardo Torrecillas Eduardo Torrecillas
Reply | Threaded
Open this post in threaded view
|

Re: Help with text files

In reply to this post by Eduardo Torrecillas

Hi Paul,

Using phrase=mgetl(fd) turns into the same result:

 phrase  =
 
 ÿþ  


Regards,


On Tue, Nov 26, 2013 at 5:22 PM, Paul Carrico <[hidden email]> wrote:

Try basicaly …

phrase=mgetl(fd)

then you’ve an array of characters …

 

Paul

 

 

 

De : users [mailto:[hidden email]] De la part de Eduardo Torrecillas
Envoyé : mardi 26 novembre 2013 19:14
À : International users mailing list for Scilab.
Objet : [Scilab-users] Help with text files

 

Hello all,

I currently have some text files and I would like to extract information from them using Scilab.
I have done this before, using mopen and mgetl, for example.

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).

Please check the attached text file.

Simple code such as:

fd=mopen('scilab_example.txt','r')

phrase=mgetl(fd,1)

Produces:

phrase=ÿp

If i still try to use mgetl, next lines are always returned as empty.

Does anybody have any clue on whats happening?

Best regards,


--
Eduardo Torrecillas
AER-09




Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection Antivirus avast! est active.



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users




--
Eduardo Torrecillas
AER-09

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Mike Page Mike Page
Reply | Threaded
Open this post in threaded view
|

Re: Help with text files

Hi Eduardo,
 
Sometimes I have had problems like this due to line termination characters.  It's possible if a file gets moved from Linux to Windows and back again, it can get unexpected CR or LF characters.  Sometimes these are read as a garbage line.  I would take a look at your text file with a hex editor to make sure the line terminations are what you expect.  Unfortunately as the file you attached got sent via email I can't tell from looking at it what was in your original file.
 
What happens when you try to read the next line?
 
HTH,
Mike.
 
-----Original Message-----
From: users [mailto:[hidden email]]On Behalf Of Eduardo Torrecillas
Sent: 26 November 2013 19:43
To: International users mailing list for Scilab.
Subject: Re: [Scilab-users] Help with text files


Hi Paul,

Using phrase=mgetl(fd) turns into the same result:

 phrase  =
 
 ÿþ  


Regards,


On Tue, Nov 26, 2013 at 5:22 PM, Paul Carrico <[hidden email]> wrote:

Try basicaly …

phrase=mgetl(fd)

then you’ve an array of characters …

 

Paul

 

 

 

De : users [mailto:[hidden email]] De la part de Eduardo Torrecillas
Envoyé : mardi 26 novembre 2013 19:14
À : International users mailing list for Scilab.
Objet : [Scilab-users] Help with text files

 

Hello all,

I currently have some text files and I would like to extract information from them using Scilab.
I have done this before, using mopen and mgetl, for example.

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).

Please check the attached text file.

Simple code such as:

fd=mopen('scilab_example.txt','r')

phrase=mgetl(fd,1)

Produces:

phrase=ÿp

If i still try to use mgetl, next lines are always returned as empty.

Does anybody have any clue on whats happening?

Best regards,


--
Eduardo Torrecillas
AER-09




Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection Antivirus avast! est active.



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users




--
Eduardo Torrecillas
AER-09

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Eduardo Torrecillas Eduardo Torrecillas
Reply | Threaded
Open this post in threaded view
|

Re: Help with text files

Hi Mike!

When I try to read the next line, it gets empty, showing [ ]

As I said, I also tried at Windows, where the files were generated, because I was thinking that transportation between OS could cause that, but maybe it's not the case since I got the same results at Windows.

Best regards,


On Tue, Nov 26, 2013 at 5:58 PM, Mike Page <[hidden email]> wrote:
Hi Eduardo,
 
Sometimes I have had problems like this due to line termination characters.  It's possible if a file gets moved from Linux to Windows and back again, it can get unexpected CR or LF characters.  Sometimes these are read as a garbage line.  I would take a look at your text file with a hex editor to make sure the line terminations are what you expect.  Unfortunately as the file you attached got sent via email I can't tell from looking at it what was in your original file.
 
What happens when you try to read the next line?
 
HTH,
Mike.
 
-----Original Message-----
From: users [mailto:[hidden email]]On Behalf Of Eduardo Torrecillas
Sent: 26 November 2013 19:43
To: International users mailing list for Scilab.
Subject: Re: [Scilab-users] Help with text files


Hi Paul,

Using phrase=mgetl(fd) turns into the same result:

 phrase  =
 
 ÿþ  


Regards,


On Tue, Nov 26, 2013 at 5:22 PM, Paul Carrico <[hidden email]> wrote:

Try basicaly …

phrase=mgetl(fd)

then you’ve an array of characters …

 

Paul

 

 

 

De : users [mailto:[hidden email]] De la part de Eduardo Torrecillas
Envoyé : mardi 26 novembre 2013 19:14
À : International users mailing list for Scilab.
Objet : [Scilab-users] Help with text files

 

Hello all,

I currently have some text files and I would like to extract information from them using Scilab.
I have done this before, using mopen and mgetl, for example.

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).

Please check the attached text file.

Simple code such as:

fd=mopen('scilab_example.txt','r')

phrase=mgetl(fd,1)

Produces:

phrase=ÿp

If i still try to use mgetl, next lines are always returned as empty.

Does anybody have any clue on whats happening?

Best regards,


--
Eduardo Torrecillas
AER-09




Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection Antivirus avast! est active.



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users




--
Eduardo Torrecillas
AER-09

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users




--
Eduardo Torrecillas
AER-09

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Antoine Monmayrant Antoine Monmayrant
Reply | Threaded
Open this post in threaded view
|

Re: Help with text files

In reply to this post by Eduardo Torrecillas
On 11/26/2013 07:13 PM, Eduardo Torrecillas wrote:
Hello all,

I currently have some text files and I would like to extract information from them using Scilab.
I have done this before, using mopen and mgetl, for example.

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).

Please check the attached text file.

Simple code such as:

fd=mopen('scilab_example.txt','r')
phrase=mgetl(fd,1)

Produces:

phrase=ÿp

If i still try to use mgetl, next lines are always returned as empty.

Does anybody have any clue on whats happening?

Best regards,

--
Eduardo Torrecillas
AER-09


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

Hi,

Here is what I found:

On my linux box, it seems your file is UTF-16:

$ file scilab_example.txt
scilab_example.txt: Little-endian UTF-16 Unicode text, with CRLF, CR line terminators

I cannot read it with mgetl, but I can use mgetstr:

-->fd=mopen('scilab_example.txt','r')
 fd  =
 
    1. 
 
-->chars=mgetstr(50)
 chars  =
 
 ��                          6 0 A     4 8 8 F / 1   
 
-->chars=mgetstr(50)
 chars  =
 
 9 - 1 9 - 2 1   4 8 8 * / 1 9 - 1 9 - 2 1     4 8   
 
-->chars=mgetstr(50)
 chars  =
 
 8 * / 1 9 - 1 9 - 2 1     4 8 8 * / 1 9 - 1 9 - 2


As you can see, it looks like a problem of encoding (the  �� or the ÿp are usually showing up when encoding is wrong).
You can solve it that way:

$ iconv -f UTF-16 -t LATIN1 scilab_example.txt > latin1.txt

than in Scilab:

-->fd=mopen('latin1.txt','r')
 fd  =
 
    1. 
 
-->phrase=mgetl(fd,1)
 phrase  =
 
              60A  488F/19-19-21 488*/19-19-21  488*/19-19-21  488*/19-19-21  

Hope it helps




_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Eduardo Torrecillas Eduardo Torrecillas
Reply | Threaded
Open this post in threaded view
|

Re: Help with text files

Hello Antoine!

Looks like the problem is solved, and actually has nothing to do with SciLab, but with file encoding!

Thank you very much!

Best regards,


On Wed, Nov 27, 2013 at 6:07 AM, Antoine Monmayrant <[hidden email]> wrote:
On 11/26/2013 07:13 PM, Eduardo Torrecillas wrote:
Hello all,

I currently have some text files and I would like to extract information from them using Scilab.
I have done this before, using mopen and mgetl, for example.

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).

Please check the attached text file.

Simple code such as:

fd=mopen('scilab_example.txt','r')
phrase=mgetl(fd,1)

Produces:

phrase=ÿp

If i still try to use mgetl, next lines are always returned as empty.

Does anybody have any clue on whats happening?

Best regards,

--
Eduardo Torrecillas
AER-09


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

Hi,

Here is what I found:

On my linux box, it seems your file is UTF-16:

$ file scilab_example.txt
scilab_example.txt: Little-endian UTF-16 Unicode text, with CRLF, CR line terminators

I cannot read it with mgetl, but I can use mgetstr:

-->fd=mopen('scilab_example.txt','r')
 fd  =
 
    1. 
 
-->chars=mgetstr(50)
 chars  =
 
 ��                          6 0 A     4 8 8 F / 1   
 
-->chars=mgetstr(50)
 chars  =
 
 9 - 1 9 - 2 1   4 8 8 * / 1 9 - 1 9 - 2 1     4 8   
 
-->chars=mgetstr(50)
 chars  =
 
 8 * / 1 9 - 1 9 - 2 1     4 8 8 * / 1 9 - 1 9 - 2


As you can see, it looks like a problem of encoding (the  �� or the ÿp are usually showing up when encoding is wrong).
You can solve it that way:

$ iconv -f UTF-16 -t LATIN1 scilab_example.txt > latin1.txt

than in Scilab:

-->fd=mopen('latin1.txt','r')
 fd  =
 
    1. 
 
-->phrase=mgetl(fd,1)
 phrase  =
 
              60A  488F/19-19-21 488*/19-19-21  488*/19-19-21  488*/19-19-21  

Hope it helps




_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users




--
Eduardo Torrecillas
AER-09

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users