<div dir="ltr"><div>Dear Jan and J-M,</div><div><br></div><div>Since I was lurking, let me chime in for a second;</div><div><br></div><div>1) ft_read_header works as it is now works for me.<br></div><div>2)
I replaced the 1 with a 0 as JM suggested, with same behaviour, so it won't break it. Although it's on line 1792 instead of 1762, I assume a typo by JM. I won't take your chance of having yoru first FieldTrip commit though :-)

</div><div>3) I have encountered this error before, but probably when reading corrupt data. I have to say, .ncs files have given me a headache when dealing with missing data (indicated by missing timestamps).</div><div>4) I tried it on a clean, fresh, Fieldtrip pull, without external neuralynx libraries. However, we do use those provided by Neuralynx (download info when you use ft_read_header), which <i>greatly </i>speeds up loading data.</div><div>5) I have had weirdly 'stuck' mex files, with unclear errors, which only restarting my computer fixed. Seriously, at least give it a shot. I wouldn't be surprised if that would work.<br></div><div><br></div><div></div><div>Let me know if I can help in another way.</div><div><br></div><div>Cheers,</div><div>Stephen<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Op wo 1 jul. 2020 om 17:14 schreef Schoffelen, J.M. (Jan Mathijs) <<a href="mailto:jan.schoffelen@donders.ru.nl">jan.schoffelen@donders.ru.nl</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div style="overflow-wrap: break-word;">
Dear Johannes,
<div><br>
</div>
<div>Welcome to the community! I am not so familiar with this fileformat, but looking in the code it seems that this is a genuine bug. I am wondering whether this has ever worked at all.</div>
<div><br>
</div>
<div>Long story short, in reading the header, it seems, as per line 177 in read_neuralynx_ncs, that both begrecord AND endrecord need to be defined as 0. However, in ft_read_header, line 1762, read_neuralynx_ncs is called with 1 and 0 as input arguments,
 rather than (what I would expect) 0 and 0. Perhaps other people might chime in here to confirm, particularly those who are reading along and who work with this fileformat themselves, but I would say that this is incorrect.</div>
<div><br>
</div>
<div>Could you try in your own code, to change the ‘1’ on line 1762 in ft_read_header into a ‘0’, and confirm that reading in of the header information then works for you?</div>
<div><br>
</div>
<div>If so, then feel free to make a PR on github for this. I know it’s a silly change, which I could easily do myself, but in the spirit of ‘we’re all in it together’ I don’t want to take the opportunity away from you :). </div>
<div><br>
</div>
<div>Of course I am just kidding, but also partly serious: if you make the suggested change in a pull request, then this improvement of the codebase will be forever in www-space associated with you (and who knows what the effect of this will be on
 your professional career, and on the grand scheme of things). This last remark is just a gentle nudge to everybody who is reading along. Oh, and did I already raise the argument that a medical degree does not forbid you to write code?</div>
<div><br>
</div>
<div><br>
</div>
<div>Best wishes,</div>
<div><br>
</div>
<div>Jan-Mathijs</div>
<div><br>
</div>
<div>
<div>
<div style="color:rgb(0,0,0)">
<div style="overflow-wrap: break-word;">
<div style="overflow-wrap: break-word;">
<div style="overflow-wrap: break-word;">
J.M.Schoffelen, MD PhD<br>
Associate PI, VIDI-fellow - PI, language in interaction<br>
Telephone: +31-24-3614793</div>
<div style="overflow-wrap: break-word;">
Physical location: room 00.028</div>
<div style="overflow-wrap: break-word;">
Donders Centre for Cognitive Neuroimaging, Nijmegen, The Netherlands<br>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div><br>
<blockquote type="cite">
<div>On 1 Jul 2020, at 16:23, Lang, Johannes <<a href="mailto:Johannes.Lang@uk-erlangen.de" target="_blank">Johannes.Lang@uk-erlangen.de</a>> wrote:</div>
<br>
<div>
<div style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif">Dear all,<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">I’m new to the community and keep running into an error using the ft_read_header function.<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB"><u></u> <u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">The way I understood the documentation<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB"><u></u> <u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">hdr = ft_read_header(‘filename’)<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB"><u></u> <u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">should read the header information into an array.<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">However, I keep running into an error<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB"><u></u> <u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">Error using read_neuralynx_ncs (line 182)<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">cannot read beyond the last record<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB"><u></u> <u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">Error in ft_read_header (line 1762)<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">    ncs = read_neuralynx_ncs(filename, 1, 0);<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB"><u></u> <u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">Not sure why this is. Has anyone had the same issue before?<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">Thanks in advance.<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB"><u></u> <u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">Kind regards,<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB"><u></u> <u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:12pt;font-family:"Times New Roman",serif" lang="EN-GB">Johannes Lang<u></u><u></u></span></div>
<div style="margin:0cm 0cm 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">
<span lang="EN-GB"><u></u> <u></u></span></div>
</div>
<span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline">_______________________________________________</span><br style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline">fieldtrip
 mailing list</span><br style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" style="color:rgb(149,79,114);text-decoration:underline;font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<a href="https://doi.org/10.1371/journal.pcbi.1002202" style="color:rgb(149,79,114);text-decoration:underline;font-family:Helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a></div>
</blockquote>
</div>
<br>
</div>
<br>
<br>
<div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<br>
</div>
</div>
</div>
</div>
</div>
</div>

_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" rel="noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</blockquote></div>