NISOx-BDI / SwE-toolbox

SwE toolbox
GNU General Public License v2.0
16 stars 7 forks source link

Reading CIfTI file based on data information saved in SwE.mat fails in Octave #171

Closed BryanGuillaume closed 4 years ago

BryanGuillaume commented 4 years ago

In Octave, it seems that reading a CIfTI file from data information saved in SwE.mat does not work. For example,

beta = swe_data_read(SwE.Vbeta(1));

error: mismatch in field names
error: called from
    swe_cifti at line 79 column 17
    subsref>rec at line 54 column 13
    subsref at line 45 column 11
    swe_data_read at line 33 column 16

However, simply reading the file by the filename seems to work perfectly. For example,

beta = swe_data_read(SwE.Vbeta(1).fname);

loads the data correctly.

In Matlab, both ways to read the data seems to work appropriately, meaning that the issue is only specific to Octave.

BryanGuillaume commented 4 years ago

It seems that the underlying issue is linked to the order of the fields in a struct array used in a call in the swe_cifti class. It seems that the order of the fields is important in Octave but not in Matlab.

Indeed the error is thrown in a call like the following:

h = swe_cifti(opt)

where opt is a struct with three fields ordered as dat, extras and hdr. Simply reordering it in a new struct as follows:

reorderedOpt = struct;
reorderedOpt.hdr = opt.hdr;
reorderedOpt.dat = opt.dat;
reorderedOpt.extras = opt.extras;

and use the reordered struct instead:

h = swe_cifti(reorderedOpt);

seems to work properly.

I am not too sure if the best solution would be to reorder each such struct object as above or to ensure that the original struct is always produced in the expected order. The simplest fix would be however to reorder it when needed and I believe I will go for this solution right now.

BryanGuillaume commented 4 years ago

This bug has been fixed in PR #166 in this commit.