StollLab / EasySpin

MATLAB toolbox for Electron Paramagnetic Resonance (EPR) spectroscopy
http://easyspin.org
MIT License
48 stars 26 forks source link

eprload: issue with loading Magnettech XML files in R2021b #228

Closed stestoll closed 2 years ago

stestoll commented 2 years ago

Loading of XML files aquired on Magnettech spectrometers fails in MATLAB R2021b.

These XML files store data in Base64 encoding. EasySpin's eprload uses the Apache Commons Codec (accessible in MATLAB as org.apache.commons.codec.binary.Base64) to decode them.

It appears that R2021b uses a newer version of the Apache Commons Codec that only decodes the initial part of the encoded string, equivalent to a single double floating point number.

The following example works in R2021a, but not in R2021b:

clc
data = 'yVs+u1W+dEA=G5zSMmK+dEA=bNxmqm6+dEA=vhz7IXu+dEA=EF2PmYe+dEA='; % encodes 5 doubles
data = typecast(int8(data),'uint8');
d = org.apache.commons.codec.binary.Base64.decodeBase64(data)
d(9:9:end) = [];
typecast(d,'double')

In R2021b, it just returns the first number. It appears that we need to implement an explicit loop in MATLAB - which will be slow.

Side note: Unlike R2021a, R2021b can handle char array input directly:

clc
data = 'yVs+u1W+dEA=G5zSMmK+dEA=bNxmqm6+dEA=vhz7IXu+dEA=EF2PmYe+dEA=';
d = org.apache.commons.codec.binary.Base64.decodeBase64(data)
typecast(d,'double')

Side note 2: Since R2016b, there exists matlab.net.base64decode (doc). Unfortunately, it also just returns one number:

clc
data = 'yVs+u1W+dEA=G5zSMmK+dEA=bNxmqm6+dEA=vhz7IXu+dEA=EF2PmYe+dEA=';
d = matlab.net.base64decode(data)
typecast(d,'double')
stestoll commented 2 years ago

Actually, the fix is very simple:

data(data=='=') = 'A';  % append 6 zero bits to pad to 9 bytes
stestoll commented 2 years ago

fixed in https://github.com/StollLab/EasySpin/commit/52bd9f5878ea6081cc43d0caa05819c7678b2f05