Back to the main page.

Bug 3455 - Reading EDF breaks on syntax errors and more

Status CLOSED WORKSFORME
Reported 2018-09-30 02:50:00 +0200
Modified 2019-08-10 12:36:52 +0200
Product: FieldTrip
Component: fileio
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P5 critical
Assigned to:
URL:
Tags:
Depends on:
Blocks:
See also:

Stephen Whitmarsh - 2018-09-30 02:50:56 +0200

Dear trippers, I've tried to use FT to convert a neuralynx .ncs file to .edf for development purposes, but ended casing some syntax errors in the FT code, but in the end have not been able to make it run successfully: fname_ncs = 'blabla.ncs'; fname_edf = 'test.edf'; dat_ncs = ft_read_data(fname_ncs); hdr_ncs = ft_read_header(fname_ncs); hdr_edf = []; hdr_edf.label = {'chan1'}; hdr_edf.Fs = hdr_ncs.Fs; ft_write_data(fname_edf,dat_ncs(1:hdr_ncs.Fs*10),'chanindx',1,'header',hdr_edf,'dataformat','edf'); hdr2_edf = ft_read_header(fname_edf); dat2_edf = ft_read_data(fname_edf); Returns the following error after the last line: >> dat2_edf = ft_read_data(fname_edf); Warning OPENEDF: Digital Minimum larger than Maximum Warning OPENEDF: Failing Physical Maximum Index exceeds matrix dimensions. Error in read_edf (line 178) if EDF.Chan_Select(k) Error in ft_read_header (line 671) hdr = read_edf(filename); Error in ft_read_data (line 185) hdr = ft_read_header(filename, 'headerformat', headerformat, 'checkmaxfilter', checkmaxfilter); The error seems to be the result of line 151* in ft_read_data returning empty because tmp is already an number: tmp = fread(EDF.FILE.FID,[8,EDF.NS],'char')'; % samples per data record EDF.SPR = str2num(char(tmp)); When I remove char/str2num (i.e. EDF.SPR = tmp), the code continues until breaking on line 197 due to a column/row typo: bi=[0;cumsum(EDF.SPR)]; Which should be: bi=[0,cumsum(EDF.SPR)]; And then again on 197: bi=[0;cumsum(EDF.SPR)]; Which should be: bi=[0,cumsum(EDF.SPR)]; At which point it break on line 330/380, at a mexfile called read_16bit, because the offset given is somehow set far too high. Now, at this point ft_read_data does at least returns a header, which clearly contains a wrong samplerate, namely 1.0323e+06 instead of 32000, as well as the wrong number of .nSamples. Something is clearly fishy, but I am lost and fished for bugs as much as I could, and that messy EDF format is not making it easy. Also, after pulling to the latest version some syntax has slightly changed changed at the points I mentioned, which makes we wonder whether a bug crept in more recently. It should be easy to replicate the bug: write then try to read some numbers to/from EDF. Best, Stephen


Jan-Mathijs Schoffelen - 2018-10-08 09:33:50 +0200

He Stephen, I cannot reproduce your problem. I am not inhibited by any knowledge concerning the particular reading/writing functions, but if I try your approach with some test neuralynx data on /home/common/, I can both write to edf, and read from it. I am on the linux cluster, using matlab2016b, using today's version of fieldtrip


Stephen Whitmarsh - 2018-10-08 09:46:51 +0200

Hi JM, Thanks a lot for checking. So strange! I'll get back to it later this week, but it's good to know its me, not FT. Best, Stephen


Jan-Mathijs Schoffelen - 2018-10-08 09:48:57 +0200

Well, it could also be me: not working for everyone, apart from me...


Stephen Whitmarsh - 2018-10-08 09:59:12 +0200

Or: neither the code, nor you, are really working, just claiming to...


Robert Oostenveld - 2019-08-10 12:36:52 +0200

This closes a whole series of bugs that have been resolved (either FIXED/WONTFIX/INVALID) for quite some time. If you disagree, please file a new issue on https://github.com/fieldtrip/fieldtrip/issues.