[scilab-Users] weird problem with fscanfMat

Antoine Monmayrant antoine.monmayrant at laas.fr
Wed Feb 9 11:41:30 CET 2011


Le 09/02/2011 10:29, Stéphane Mottelet a écrit :
> Le 09/02/2011 10:07, Antoine Monmayrant a écrit :
>> Le 09/02/2011 09:26, Stéphane Mottelet a écrit :
>>> Le 09/02/2011 09:24, Antoine Monmayrant a écrit :
>>>> Le 08/02/2011 22:04, Stephane Mottelet a écrit :
>>>>> Hi all,
>>>>>
>>>>> I cannot manage to read the attached file with
>>>>> fscanfMat, although it has a compatible structure,
>>>>> i.e. one line one text then many lines of the same
>>>>> number of columns.
>>>>>
>>>>> I have even tried to read the first line with mgetl,
>>>>> but then eof is reached although I only get the first line
>>>>> (composed of text).
>>>>>
>>>>> I know each line is only finished with a cr and not
>>>>> an eol. Is it a problem ?
>>>>> Thanks for help of anybody willing to solve this
>>>>> weird issue !!!
>>>>>
>>>>> S.
>>>> When I open the file you attached to your email, I don't see any 
>>>> separator to mark the end of line (no cr, no \n, no nothing).
>>>> It might have been mangled by my mail program but I doubt it.
>>>> I managed to open it in scilab with read_csv and it also looks like 
>>>> there is no separator at the end of line: the last item of a line 
>>>> is touching the first item on next line:
>>>>
>>>> -->a_string=read_csv("20101122_VOLUME.txt","\t");
>>>>
>>>> -->a_string(16)
>>>> ans  =
>>>>
>>>>  ch15 (L)0.000
>>>>
>>>> -->a_string(31)
>>>>  ans  =
>>>>
>>>>  0.0000.001
>>>>
>>>> -->a_string(46)
>>>>  ans  =
>>>>
>>>>  0.0000.002
>>>>
>>>>
>>>> Hope it helps,
>>>>
>>>> Antoine
>>>>
>>> Well, when I open it with vi, I see some ^M at the end of each line.
>>>
>>> S.
>> I don't, so it has been mangled in the process.
>> With :set list, I can see the column separator (^I), but nothing at 
>> the end of line, the two adjacent items being merged...
>>
>> Antoine
>> PS: I join your file back, can you check if it has been modified or not?
> The ^M are missing, you are right. I join the original
> file (still unreadable with fscanfMat), but zipped in order
> to preserve it.
>
> S.
Got it!
There is a problem with your file format.
It might be a bug in fscanfMat, but I don't think as it is only supposed 
to open files created with fprintfMat.
As such, it does not handle the slightest deviation from the expect format.
Here is a way to correct things under linux:

cat 20101122_VOLUME.txt | tr '\r' '\n' > corr_20101122_VOLUME.txt

then in scilab you can load it:

-->dat=fscanfMat("corr_20101122_VOLUME.txt");

-->size(dat)
  ans  =

     291.    16.

Antoine



More information about the users mailing list