diff --git a/@xmltree/Contents.m b/@xmltreemod/Contents.m similarity index 100% rename from @xmltree/Contents.m rename to @xmltreemod/Contents.m diff --git a/@xmltree/LICENSE b/@xmltreemod/LICENSE similarity index 100% rename from @xmltree/LICENSE rename to @xmltreemod/LICENSE diff --git a/@xmltree/add.m b/@xmltreemod/add.m similarity index 100% rename from @xmltree/add.m rename to @xmltreemod/add.m diff --git a/@xmltree/attributes.m b/@xmltreemod/attributes.m similarity index 100% rename from @xmltree/attributes.m rename to @xmltreemod/attributes.m diff --git a/@xmltree/branch.m b/@xmltreemod/branch.m similarity index 98% rename from @xmltree/branch.m rename to @xmltreemod/branch.m index 9f24ebf..055808c 100644 --- a/@xmltree/branch.m +++ b/@xmltreemod/branch.m @@ -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); diff --git a/@xmltree/char.m b/@xmltreemod/char.m similarity index 100% rename from @xmltree/char.m rename to @xmltreemod/char.m diff --git a/@xmltree/children.m b/@xmltreemod/children.m similarity index 100% rename from @xmltree/children.m rename to @xmltreemod/children.m diff --git a/@xmltree/convert.m b/@xmltreemod/convert.m similarity index 100% rename from @xmltree/convert.m rename to @xmltreemod/convert.m diff --git a/@xmltree/copy.m b/@xmltreemod/copy.m similarity index 100% rename from @xmltree/copy.m rename to @xmltreemod/copy.m diff --git a/@xmltree/delete.m b/@xmltreemod/delete.m similarity index 100% rename from @xmltree/delete.m rename to @xmltreemod/delete.m diff --git a/@xmltree/display.m b/@xmltreemod/display.m similarity index 100% rename from @xmltree/display.m rename to @xmltreemod/display.m diff --git a/@xmltree/editor.m b/@xmltreemod/editor.m similarity index 100% rename from @xmltree/editor.m rename to @xmltreemod/editor.m diff --git a/@xmltree/find.m b/@xmltreemod/find.m similarity index 100% rename from @xmltree/find.m rename to @xmltreemod/find.m diff --git a/@xmltree/flush.m b/@xmltreemod/flush.m similarity index 100% rename from @xmltree/flush.m rename to @xmltreemod/flush.m diff --git a/@xmltree/get.m b/@xmltreemod/get.m similarity index 100% rename from @xmltree/get.m rename to @xmltreemod/get.m diff --git a/@xmltree/getfilename.m b/@xmltreemod/getfilename.m similarity index 100% rename from @xmltree/getfilename.m rename to @xmltreemod/getfilename.m diff --git a/@xmltree/isfield.m b/@xmltreemod/isfield.m similarity index 100% rename from @xmltree/isfield.m rename to @xmltreemod/isfield.m diff --git a/@xmltree/length.m b/@xmltreemod/length.m similarity index 100% rename from @xmltree/length.m rename to @xmltreemod/length.m diff --git a/@xmltree/move.m b/@xmltreemod/move.m similarity index 100% rename from @xmltree/move.m rename to @xmltreemod/move.m diff --git a/@xmltree/parent.m b/@xmltreemod/parent.m similarity index 100% rename from @xmltree/parent.m rename to @xmltreemod/parent.m diff --git a/@xmltree/private/compile_mex.sh b/@xmltreemod/private/compile_mex.sh similarity index 100% rename from @xmltree/private/compile_mex.sh rename to @xmltreemod/private/compile_mex.sh diff --git a/@xmltree/private/struct2xml.m b/@xmltreemod/private/struct2xml.m similarity index 99% rename from @xmltree/private/struct2xml.m rename to @xmltreemod/private/struct2xml.m index a5a506b..7958cc5 100644 --- a/@xmltree/private/struct2xml.m +++ b/@xmltreemod/private/struct2xml.m @@ -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); diff --git a/@xmltree/private/xml_findstr.c b/@xmltreemod/private/xml_findstr.c similarity index 100% rename from @xmltree/private/xml_findstr.c rename to @xmltreemod/private/xml_findstr.c diff --git a/@xmltree/private/xml_findstr.m b/@xmltreemod/private/xml_findstr.m similarity index 100% rename from @xmltree/private/xml_findstr.m rename to @xmltreemod/private/xml_findstr.m diff --git a/@xmltree/private/xml_findstr.mexa64 b/@xmltreemod/private/xml_findstr.mexa64 similarity index 100% rename from @xmltree/private/xml_findstr.mexa64 rename to @xmltreemod/private/xml_findstr.mexa64 diff --git a/@xmltree/private/xml_findstr.mexw64 b/@xmltreemod/private/xml_findstr.mexw64 similarity index 100% rename from @xmltree/private/xml_findstr.mexw64 rename to @xmltreemod/private/xml_findstr.mexw64 diff --git a/@xmltree/private/xml_parser.m b/@xmltreemod/private/xml_parser.m similarity index 100% rename from @xmltree/private/xml_parser.m rename to @xmltreemod/private/xml_parser.m diff --git a/@xmltree/root.m b/@xmltreemod/root.m similarity index 100% rename from @xmltree/root.m rename to @xmltreemod/root.m diff --git a/@xmltree/save.m b/@xmltreemod/save.m similarity index 100% rename from @xmltree/save.m rename to @xmltreemod/save.m diff --git a/@xmltree/save_string.m b/@xmltreemod/save_string.m similarity index 100% rename from @xmltree/save_string.m rename to @xmltreemod/save_string.m diff --git a/@xmltree/set.m b/@xmltreemod/set.m similarity index 100% rename from @xmltree/set.m rename to @xmltreemod/set.m diff --git a/@xmltree/setfilename.m b/@xmltreemod/setfilename.m similarity index 100% rename from @xmltree/setfilename.m rename to @xmltreemod/setfilename.m diff --git a/@xmltree/xmltree.m b/@xmltreemod/xmltreemod.m similarity index 92% rename from @xmltree/xmltree.m rename to @xmltreemod/xmltreemod.m index c1dde3a..df54dbb 100644 --- a/@xmltree/xmltree.m +++ b/@xmltreemod/xmltreemod.m @@ -1,4 +1,4 @@ -function tree = xmltree(varargin) +function tree = xmltreemod(varargin) % XMLTREE/XMLTREE Constructor of the XMLTree class % FORMAT tree = xmltree(varargin) % @@ -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}) @@ -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 diff --git a/cifti_write.m b/cifti_write.m index 5bbe08f..f002ae4 100644 --- a/cifti_write.m +++ b/cifti_write.m @@ -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; diff --git a/private/cifti_parse_xml.m b/private/cifti_parse_xml.m index 32a2c1f..325b74b 100644 --- a/private/cifti_parse_xml.m +++ b/private/cifti_parse_xml.m @@ -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 diff --git a/private/cifti_write_xml.m b/private/cifti_write_xml.m index f962157..474c56b 100644 --- a/private/cifti_write_xml.m +++ b/private/cifti_write_xml.m @@ -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'); @@ -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'); @@ -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 @@ -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 @@ -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; @@ -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