<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Scott - <div><br></div><div>Thanks for the e-mail - it's a good point. </div><div><br></div><div>The difficulty arises because fiff_setup_read_raw (called by ft_read_header) leaves the .fif file open to be read (it stores the fid in its output structure raw.fid, i.e. hdr.orig.raw.fid for fieldtrip). Unfortunately if we closed it at this stage (i.e. within ft_read_header), fiff_read_raw_segment, which is called by ft_read_data/ft_read_event, doesn't know where to look for the file - it expects a structure to be returned by fiff_setup_read_raw with an open file. Again, we could close the file after calling fiff_read_raw_segment in ft_read_data, but this would assume that ft_read_data/ft_read_event is only going to be called once, whereas some users might want to use hdr=ft_read_header once and then keep on using ft_read_data with same hdr structure, in which case we need to keep the file open.</div><div><br></div><div>Unless you can think of a better solution, my suggestion would be first to call </div><div><br></div><div>hdr=ft_read_header(fname);</div><div><br></div><div>in your script, then supply this hdr to your calls to ft_read_event/ft_read_data (this should hopefully prevent the file being opened multiple times), and then once you have done all the reading, close that file with</div><div><br></div><div>fclose(hdr.orig.raw.fid);</div><div><br></div><div>Hopefully that will stop you clogging up matlab with open files. Let me know if it works or not.</div><div><br></div><div>Cheers,</div><div>Laurence</div><div><br></div><div><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div class="AppleMailSignature" id="17D31EC3-297A-4FA6-B7EE-EE06DE0A8243"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">===========================================</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Laurence Hunt, DPhil Student</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "> Centre for Functional MRI of the Brain (FMRIB), </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">University of Oxford</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="mailto:lhunt@fmrib.ox.ac.uk">lhunt@fmrib.ox.ac.uk</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Phone: (+44)1865-(2)22738</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">===========================================</div></div></div></div></div></span></div></span></div></span></span>
</div>
<br><div><div>On 4 Feb 2011, at 16:12, Scott Burns wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">FieldTrip Experts -<div><br></div><div>I'm building a FieldTrip pipeline for use on M/EEG data collected on a Neuromag 306 system.  Because I'm looping over subjects (13 currently), event type (5 unique events), and number of runs (4), there's lots of preprocessing to do.  After processing a certain amount of files, MATLAB refuses to open more files. </div><div><br></div><div>I ran 'lsof MATLAB | grep "/autofs/cluster/kuperberg/" (to only include the data files I'm using, not MATLAB's system files) and found that for every innermost loop, my script is opening the .fif file twice and not releasing it.  I use a custom function for ft_definetrial and in that I use ft_read_event (that operates on the .fif file). After defining trials, I use ft_preprocessing.</div><div><br></div><div>I would venture to guess that both ft_read_event and ft_read_data (ft_preprocessing:line 492) are either 1) not closing files they've opened (presumably through MNE functions), or 2) they're using shared code that doesn't close files.  I use MNE and haven't run into this issue before.  That being said, fclose('all') does close all these files but I think it's still worth looking into.</div><div><br></div><div>FWIW I'm using CentOS 5 and MATLAB R2010B (glnxa64).</div><div><br></div><div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Scott Burns</div><div>Kuperberg Lab</div><div>Martinos Center for Biomedical Imaging</div><div><a href="mailto:sburns@nmr.mgh.harvard.edu">sburns@nmr.mgh.harvard.edu</a></div><div><br></div><div><span class="Apple-style-span" style="border-collapse: collapse; "><font class="Apple-style-span" face="Arial" size="1"><span class="Apple-style-span" style="font-size: 9px; ">The information in this e-mail is intended only for the person to whom it is addressed. If you believe this e-mail was sent to you in error and the e-mail contains patient information, please contact the Partners Compliance HelpLine at </span></font><a href="http://www.partners.org/complianceline" target="_blank"><font class="Apple-style-span" face="Arial" size="1"><span class="Apple-style-span" style="font-size: 9px; "><font class="Apple-style-span">http://www.partners.org/<wbr>complianceline</font></span></font></a><font class="Apple-style-span" face="Arial" size="1"><span class="Apple-style-span" style="font-size: 9px; "> . If the e-mail was sent to you in error but does not contain patient information, please contact the sender and properly dispose of the e-mail.</span></font></span></div><div><br></div></div></span><br class="Apple-interchange-newline"></span><br class="Apple-interchange-newline">
</div>
<br></div></div>_______________________________________________<br>fieldtrip mailing list<br><a href="mailto:fieldtrip@donders.ru.nl">fieldtrip@donders.ru.nl</a><br>http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</blockquote></div><br></div></body></html>