issue with read_ctf_res4.m: use of uinit8 and char in fread

Erick Britis Ortiz Erick.Ortiz at MED.UNI-TUEBINGEN.DE
Fri Jul 25 19:38:15 CEST 2008

Dear Robert,

Here is the configuration of the systems were the issue was observed:
- Linux: MATLAB 7.5.0 (R2007b)
System language: German (LANG=de_DE.UTF-8)
- Windows XP: MATLAB 7.0.1 (R14)
System language: Brazilian Portuguese

It turns out, it had to do with two things. First, on reproducing it, I
noticed another change that is necessary to tackle the issue: long ago,
I included the channel UDIO001 in read_ctf_trigger.m, what I thought was
a "my-system-only" change. But without it, it still finds 0 events,
confirmed both in Linux and Windows. I am sending my read_ctf_trigger.m
for reviewing also. In the Windows machine, this was enough to solve the

Second, the language settings: I looked up which encoding was used when
a file is opened by using:
[filename, permission, machineformat, encoding] = fopen(fid)

And the values returned were 'UTF-8' in the Linux machine and an empty
string in the Windows one. Changing the LANG to de_DE on Linux gave me
the value 'ISO-8859-1' for encoding, but the problem was only solved
when I replaced read_ctf_trigger.m. Finally, changing char to uint8 in
read_ctf_res4.m made it robust against locale changes.

Maybe the issue has not been noticed before because it is inside a
try-catch block (in fact, some layers of try-catch to get to fread), so
usually it fails silently. I noticed some odd behaviour on file handling
since I started to use Fieldtrip, but it took some time to get to the
exact point and I do not know to which extent using another trigger
channel would prevent the problem from happening. Additionally, MATLAB
changed the file handling in a recent version, so it might happen that
people using older versions also do not see it.

Best regards,

Robert Oostenveld wrote:
> Hi Erick
> Thanks for the suggested change. I have incoroprated it and it will be
> included in tonights release version on the ftp.
> The char/int8 problem had been reported before, but I have never seen it
> happen myself on any of the computers that I have been working with. Do
> you think that it might be related to particular language settings on
> the computer that you are using? Since it not always occuring to me
> seems to indicate that Matlab sometimes wants to use 8 bit and sometimes
> 16 bit wide characters.
> Actually there is a lot of reading code for other (non ctf) formats that
> also uses fread(...'char'). That code should also be affected with the
> bug, which means that I should make the suggested change everywhere
> where chars are read.
> best regards,
> Robert
> On 21 Jul 2008, at 20:06, Erick Britis Ortiz wrote:
>> I think that this problem is due to a change in fread's behaviour: as
>> nowadays characters are not always 8-bit wide, we are supposed to use
>> 'uint8' instead of 'char'. This change has been responsible for some
>> nasty problems, including this one.
>> As of 20080720 version of Fieldtrip, the snapshot still showed this
>> behavior. Herewith I am attaching a correction of read_ctf_res4.m.
>> Hope that some of you who have had similar problem might find it helpful.
> ----------------------------------
> The aim of this list is to facilitate the discussion between users of
> the FieldTrip  toolbox, to share experiences and to discuss new ideas
> for MEG and EEG analysis. See also
> and

The aim of this list is to facilitate the discussion between users of the FieldTrip  toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis. See also and
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: read_ctf_trigger.m
URL: <>

More information about the fieldtrip mailing list