External Email - Use Caution        

Hello FreeSurfer Developers,

I found what I believe to be a bug. Typically I can load mgz files into my 
Matlab program without any trouble. 
But if the path containing the mgz file has a space then I get an error.

When I run this very short script in Matlab calling the MRIread function 
(/Applications/freesurfer/7.4.1/matlab/MRIread.m):

filepath = char("/Users/user/Documents/folder space test/data/mri.mgz");
mri = MRIread(filepath);

I get the following error:

gunzip: can't stat: /Users/user/Documents/folder 
(/Users/user/Documents/folder.gz): No such file or directory
gunzip: can't stat: space (space.gz): No such file or directory
gunzip: can't stat: test/data/mri.mgz (test/data/mri.mgz.gz): No such file or 
directory

ERROR: problem reading fname
SWITCH expression must be a scalar or a character vector.

Error in load_mgh (line 163)
switch type

Error in MRIread (line 90)
[mri.vol, M, mr_parms, volsz] = load_mgh(fspec,[],[],headeronly);

Error in test_load_mgz (line 2)
mri = MRIread(filepath);

I traced this down to the function load_mgh.m 
(/Applications/freesurfer/7.4.1/matlab/load_mgh.m) where a file path string 
(char array) is dynamically populated with randomly generated folder names to 
unzip into. 
It's about line 69 and looks like this:
[status,msg] = unix(sprintf('gunzip -c %s > %s', fname, new_fname));

You may notice that potential spaces in the path names fname and new_fname are 
not escaped with single quotes. 
I edited the file to escape the parameterized strings like so:
[status,msg] = unix(sprintf("gunzip -c '%s' > '%s'", fname, new_fname));

This solved the problem for me.

Computer details:
OS: MacOS Sonoma (latest)
Chipset: Apple M1 (aarch64)
Calling Program: Matlab R2023b
Freesurfer: 7.4.1

Thank you for your time.

Sincerely,
Tyler Slouf
_______________________________________________
Freesurfer mailing list
Freesurfer@nmr.mgh.harvard.edu
https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer
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 Mass General Brigham 
Compliance HelpLine at https://www.massgeneralbrigham.org/complianceline 
<https://www.massgeneralbrigham.org/complianceline> .
Please note that this e-mail is not secure (encrypted).  If you do not wish to 
continue communication over unencrypted e-mail, please notify the sender of 
this message immediately.  Continuing to send or respond to e-mail after 
receiving this message means you understand and accept this risk and wish to 
continue to communicate over unencrypted e-mail. 

Reply via email to