gllmflndn / gifti

MATLAB/Octave GIfTI Library
https://www.gllmflndn.com/software/matlab/gifti/
MIT License
25 stars 12 forks source link

Deal with empty meta-data header #12

Closed smazurchuk closed 9 months ago

smazurchuk commented 2 years ago

I ran into this problem running FSL's PALM. It seems that this is not a problem with PALM116 and Octave, but PALM119 and Matlab (2020b) fail when fprintf runs into an empty cell.

I can upload files and commands that fail if you'd like to see the problem

smazurchuk commented 2 years ago

If you happen to have palm installed and want to see the error in action, it can be replicated with the following file and command

input file: https://github.com/smazurchuk/smazurchuk.github.io/raw/master/assets/tmpFiles/lh.func.gii surface file: https://github.com/smazurchuk/smazurchuk.github.io/raw/master/assets/tmpFiles/S1200.L.midthickness_MSMAll.32k_fs_LR.surf.gii command: palm -i lh.func.gii -s S1200.L.midthickness_MSMAll.32k_fs_LR.surf.gii -n 100 -C 3.1 -ise -Cstat extent -logp

This problem might also be of interest to @andersonwinkler

gllmflndn commented 2 years ago

Thank you for this, @smazurchuk

I will have a look in a few days and in the meantime I was just checking the header of file lh.func.gii and it contains the following:

   <MetaData>
      <MD>
         <Name><![CDATA[Name]]></Name>
         <Value><![CDATA[]]></Value>
      </MD>
   </MetaData>

Is this what is triggering the problem you are encountering?

smazurchuk commented 2 years ago

Hey Thanks. Yea, as far as I can tell, it is. The gifti is the direct output of wb_command -cifti-seperate on a cifti file. Like I said above, the files and command above will work fine with Octave+Palm116 but fail for Matlab_Palm119, so fprintf must handle empty cells differently or the behavior changed, but I haven't explored it in more detail.

gllmflndn commented 2 years ago

Hi @smazurchuk Sorry for the wait. I can reproduce the issue with both MATLAB and Octave using the current version of PALM (from GitHub). My guess is that PALM 116 and 119 use a different version of the GIfTI/XML parser, and with the new version, the MetaData with an empty value returns {} instead of '' as before. Could you confirm the problem is fixed if this line: https://github.com/gllmflndn/gifti/blob/main/%40gifti/private/gifti_read.m#L235 is changed to be:

if isempty(uid), value = ''; return; end

I am still not sure it is the right place for the fix but it is getting closer.

smazurchuk commented 9 months ago

Sorry for never responding! The change in the above line removes the problem for me! The new code in gifti_read.m is the following

image

gllmflndn commented 9 months ago

Thanks 😄 I now pushed that change in https://github.com/gllmflndn/gifti/commit/df62cefecd65d2e03c7f16faadc874af759fdbe.