Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

parseCCF.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. function CCF = parseCCF(varargin)
  2. % parseCCF
  3. %
  4. % Parses an XML CCF file.
  5. %
  6. % Nick Halper
  7. % support@blackrockmicro.com
  8. % Blackrock Microsystems
  9. % Version 1.1.0.0
  10. %
  11. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  12. % Version History
  13. %
  14. % 1.0.0.0:
  15. % - Initial release.
  16. %
  17. % 1.1.0.0: January 18, 2016 - Kian Torab
  18. % - Minor bug fix with file loading.
  19. %
  20. % 1.1.1.0: January 19, 2016 - Kian Torab
  21. % - Added a progress bar.
  22. %
  23. % 1.1.2.0: October 20, 2016 - Saman Hagh-gooie
  24. % - Fixed a invalid character bug.
  25. % - Bug fixes with file loading
  26. %
  27. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  28. if nargin ~= 0
  29. fullfilename = varargin{1};
  30. else
  31. fullfilename = [];
  32. end
  33. if ~exist(fullfilename, 'file')
  34. [fileName pathName] = getFile('*.ccf', 'Choose a CCF file...');
  35. fullfilename = [pathName fileName];
  36. else
  37. [pathName, fileName, ext] = fileparts(fullfilename);
  38. pathName = [pathName];
  39. fileName = [fileName, ext];
  40. end
  41. prevDecodedXMLCCF = [fullfilename(1:end-3) 'xmld'];
  42. if exist(prevDecodedXMLCCF, 'file') == 2
  43. load(prevDecodedXMLCCF, '-mat');
  44. return;
  45. end
  46. disp('The CCF loading can take up to half an hour the first time. Please be patient.');
  47. OBJ = xmlread(fullfile(pathName,fileName));
  48. removeIndentNodes(OBJ.getChildNodes);
  49. CCF = parseChildNodes(OBJ);
  50. save(prevDecodedXMLCCF, 'CCF');
  51. %function children = parseChildNodes(OBJ)
  52. function children = parseChildNodes(theNode)
  53. % Recurse over node children.
  54. children = 0;
  55. if theNode.hasChildNodes
  56. childNodes = theNode.getChildNodes;
  57. numChildNodes = childNodes.getLength;
  58. allocCell = cell(1, numChildNodes);
  59. children = struct( ...
  60. 'Name', allocCell, 'Attributes', allocCell, ...
  61. 'Data', allocCell, 'Children', allocCell);
  62. counter=0; % added by SH 05.oct.2016
  63. for count = 1:numChildNodes
  64. theChild = childNodes.item(count-1);
  65. children(count) = makeStructFromNode(theChild);
  66. counter = counter + 1;
  67. if mod(counter,20) == 0
  68. fprintf('.');
  69. end
  70. end
  71. end
  72. %function nodeStruct - makeStructFromNode(OBJ)
  73. function nodeStruct = makeStructFromNode(theNode)
  74. nodeStruct = struct(...
  75. 'Name',char(theNode.getNodeName),...
  76. 'Attributes', parseAttributes(theNode),...
  77. 'Data','',...
  78. 'Children', parseChildNodes(theNode));
  79. if any(strcmp(methods(theNode), 'getData'))
  80. nodeStruct.Data = char(theNode.getData);
  81. else
  82. nodeStruct.Data = '';
  83. end
  84. function attributes = parseAttributes(theNode)
  85. % Create attributes structure.
  86. attributes = [];
  87. if theNode.hasAttributes
  88. theAttributes = theNode.getAttributes;
  89. numAttributes = theAttributes.getLength;
  90. allocCell = cell(1, numAttributes);
  91. attributes = struct('Name', allocCell, 'Value', ...
  92. allocCell);
  93. for count = 1:numAttributes
  94. attrib = theAttributes.item(count-1);
  95. attributes(count).Name = char(attrib.getName);
  96. attributes(count).Value = char(attrib.getValue);
  97. end
  98. end
  99. function removeIndentNodes( childNodes )
  100. numNodes = childNodes.getLength;
  101. remList = [];
  102. counter = 0;
  103. for i = numNodes:-1:1
  104. counter = counter + 1;
  105. if rem(counter,20) == 0
  106. fprintf('.');
  107. end
  108. theChild = childNodes.item(i-1);
  109. if (theChild.hasChildNodes)
  110. removeIndentNodes(theChild.getChildNodes);
  111. else
  112. if ( theChild.getNodeType == theChild.TEXT_NODE && ...
  113. ~isempty(char(theChild.getData())) && ...
  114. all(isspace(char(theChild.getData()))))
  115. remList(end+1) = i-1; % java indexing
  116. end
  117. end
  118. end
  119. for i = 1:length(remList)
  120. childNodes.removeChild(childNodes.item(remList(i)));
  121. end