Skip to content

Commit

Permalink
rename modified xmltree to avoid collision, reduce excess whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
coalsont committed Nov 16, 2021
1 parent a3da947 commit f36f23c
Show file tree
Hide file tree
Showing 36 changed files with 31 additions and 14 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion @xmltree/branch.m → @xmltreemod/branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
error('[XMLTree] Invalid UID.');
end

subtree = xmltree;
subtree = xmltreemod;
subtree = set(subtree,root(subtree),'name',tree.tree{uid}.name);
%- fix by Piotr Dollar to copy attributes for the root node:
subtree = set(subtree,root(subtree),'attributes',tree.tree{uid}.attributes);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
end

% Create an empty XML tree
tree = xmltree;
tree = xmltreemod;

% Root element is the input argument name
tree = set(tree,root(tree),'name',rootname);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions @xmltree/xmltree.m → @xmltreemod/xmltreemod.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function tree = xmltree(varargin)
function tree = xmltreemod(varargin)
% XMLTREE/XMLTREE Constructor of the XMLTree class
% FORMAT tree = xmltree(varargin)
%
Expand All @@ -25,9 +25,9 @@
'parent',[],...
'uid',1);
tree.filename = '';
tree = class(tree,'xmltree');
tree = class(tree,'xmltreemod');

elseif isa(varargin{1},'xmltree')
elseif isa(varargin{1},'xmltreemod')
tree = varargin{1};

elseif ischar(varargin{1})
Expand All @@ -47,7 +47,7 @@
tree.tree = xml_parser(xmlstr);
tree.filename = varargin{1};
end
tree = class(tree,'xmltree');
tree = class(tree,'xmltreemod');

elseif isstruct(varargin{1})
if nargin > 1
Expand Down
2 changes: 1 addition & 1 deletion cifti_write.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function cifti_write(cifti, filename, varargin)
% >> cifti.cdata = outdata;
% >> cifti.diminfo{2} = cifti_diminfo_make_scalars(size(outdata, 2));
% >> cifti_write(cifti, 'ciftiout.dscalar.nii');
libversion = '2.0.0';
libversion = '2.0.1';
options = myargparse(varargin, {'stacklevel', 'disableprovenance', 'keepmetadata'}); %stacklevel is an implementation detail, don't add to help
if isempty(options.stacklevel) %stacklevel is so that so it doesn't get "ciftisave" all the time
options.stacklevel = 2;
Expand Down
2 changes: 1 addition & 1 deletion private/cifti_parse_xml.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if any(nulls)
bytes = bytes(1:(find(nulls, 1) - 1));
end
tree = xmltree(bytes);
tree = xmltreemod(bytes);
setfilename(tree, filename);%probably helps with error messages for malformed XML?
attrs = myattrs(tree);
for attr = attrs
Expand Down
29 changes: 23 additions & 6 deletions private/cifti_write_xml.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
cifti.metadata = cifti_metadata_set(cifti.metadata, 'ParentProvenance', prov);
end
end
tree = xmltree();
tree = xmltreemod();
root_uid = root(tree);
tree = set(tree, root_uid, 'name', 'CIFTI');
tree = attributes(tree, 'add', root_uid, 'Version', '2');
Expand Down Expand Up @@ -79,7 +79,7 @@
tree = attributes(tree, 'add', model_uid, 'ModelType', 'CIFTI_MODEL_TYPE_SURFACE');
tree = attributes(tree, 'add', model_uid, 'SurfaceNumberOfVertices', num2str(model{1}.numvert));
[tree, vert_uid] = add(tree, model_uid, 'element', 'VertexIndices');
tree = add(tree, vert_uid, 'chardata', matrix2str(model{1}.vertlist(:)')); %NOTE: 0-based vertex indices
tree = add(tree, vert_uid, 'chardata', matrix2str_int(model{1}.vertlist(:)')); %NOTE: 0-based vertex indices
case 'vox'
if size(model{1}.voxlist, 1) == model{1}.count && size(model{1}.voxlist, 2) == 3
warning('model voxel list appears to be transposed');
Expand All @@ -96,7 +96,7 @@
end
tree = attributes(tree, 'add', model_uid, 'ModelType', 'CIFTI_MODEL_TYPE_VOXELS');
[tree, vox_uid] = add(tree, model_uid, 'element', 'VoxelIndicesIJK');
tree = add(tree, vox_uid, 'chardata', matrix2str(model{1}.voxlist'));
tree = add(tree, vox_uid, 'chardata', matrix2str_int(model{1}.voxlist'));
otherwise
error(['unrecignized brain model type "' model{1}.type '"']);
end
Expand Down Expand Up @@ -167,7 +167,24 @@
tree = add(tree, tfm_uid, 'chardata', matrix2str(modsform));
end

%TODO: num2str(..., 6) on a matrix adds a *lot* of whitespace, fix?
%num2str(..., 6) on a matrix adds a *lot* of whitespace, so make a version for integers
function outstring = matrix2str_int(input)
%matlab 2016a doesn't have join(), so we can't write a one-liner
matchar = num2str(input);
expectedlength = length(matchar(:)) + size(matchar, 1);
outstring = char(zeros(1, expectedlength, 'int8'));
curpos = 1;
for i = 1:size(matchar, 1)
addstring = [char(10) matchar(i, :)]; %hack: xml looks better with a newline before the matrix
outstring(curpos:(curpos + length(addstring) - 1)) = addstring;
curpos = curpos + length(addstring);
end
if any(outstring == 0) %check for bad length computation
warning('internal problem in cifti xml matrix2str()');
outstring(outstring == 0) = []; %delete the nulls
end
end

function outstring = matrix2str(input)
%matlab 2016a doesn't have join(), so we can't write a one-liner
matchar = num2str(input, 6); %6 significant figures for float improves round-trip consistency
Expand Down Expand Up @@ -216,7 +233,7 @@
error('invalid voxlist content in cifti struct');
end
[tree, vox_uid] = add(tree, parcel_uid, 'element', 'VoxelIndicesIJK');
tree = add(tree, vox_uid, 'chardata', matrix2str(map.parcels(i).voxlist'));
tree = add(tree, vox_uid, 'chardata', matrix2str_int(map.parcels(i).voxlist'));
end
for j = 1:length(map.parcels(i).surfs)
numverts = -1;
Expand All @@ -234,7 +251,7 @@
end
[tree, vert_uid] = add(tree, parcel_uid, 'element', 'Vertices');
tree = attributes(tree, 'add', vert_uid, 'BrainStructure', friendly_to_cifti_structure(map.parcels(i).surfs(j).struct));
tree = add(tree, vert_uid, 'chardata', matrix2str(map.parcels(i).surfs(j).vertlist));
tree = add(tree, vert_uid, 'chardata', matrix2str_int(map.parcels(i).surfs(j).vertlist));
end
end
end
Expand Down

0 comments on commit f36f23c

Please sign in to comment.