e0404/matRad

[BUG] Warning and error messages in matRad_readNRRD fail, string concatenation is wrong when lineContent is an empty cell

zperko opened this issue · 2 comments

Describe the bug
When reading NRRD files and seeing empty lines or other content for which a warning/error is raised, the warning/error messages themselves are wrong, the string concatenation doesn't work with lineContent being an empty cell.

To Reproduce
Read and NRRD file that would raise a warning/error according to the lineConcent in matRad_readNRRD.m

Expected behavior
Error/warning line just executes properly, raising the error/warning.

Solution
The strings in the warning/error messages should be properly formatted, an exception for empty cell should work. Might be an issue in several other functions too.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. Windows]
  • Environment & Version [e.g. Matlab 2020b]
  • matRad Version [e.g. 2.10.0] If developing with git, state the branch and commit ID, if possible

Additional context
Add any other context about the problem here.

For lines 63 and 71 lineContent should probably be currentLine

wahln commented

Yeah, this block:

lineContent = regexp(currentLine, '(.+):(=|\s)(.+)', 'tokens');
if isempty(lineContent)
warning(['Could not parse line: "' lineContent '"']);
elseif isequal(lineContent{1}{2},' ') %space after colon refers to "field"
nrrdMetaData.fields{end+1,1} = lineContent{1}{1}; %Fieldname
nrrdMetaData.fields{end,2} = lineContent{1}{3}; %Information
elseif isequal(lineContent{1}{2},'=') %= after colon refers to key-value pair
nrrdMetaData.keys{end+1,1} = lineContent{1}{1}; %Key
nrrdMetaData.keys{end,2} = lineContent{1}{3}; %Value
else
warning(['Could not parse line: "' lineContent '"']);

We should replace the formatting like we do in other functions using the printf-like syntax and, as you said, in line 63 and 71, use currentLine.