Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@xml/xmlread.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % XMLREAD Reads a XML object | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: XMLREAD Reads a XML object. | |
5 % | |
6 % CALL: obj = xmlread(node); | |
7 % obj = xmlread(node ,'class'); | |
8 % obj = xmlread(node ,'ao'); | |
9 % obj = xmlread(node ,'time'); | |
10 % | |
11 % XML HIERARCHY: ---------------------- ltpda_object ---------------------- | |
12 % | |
13 % <ltpda_object> | |
14 % | |
15 % --> <object> ... | |
16 % --> <cell> ... | |
17 % | |
18 % </ltpda_object> | |
19 % | |
20 % ------------------------- object ------------------------- | |
21 % | |
22 % <object> ('type' - attribute) | |
23 % | |
24 % <property> ... | |
25 % | |
26 % </object> | |
27 % | |
28 % ------------------------ property ------------------------ | |
29 % -------------------------- cell -------------------------- | |
30 % | |
31 % <property> ('type', 'prop_name' -attributes) | |
32 % OR <cell> ('type' -attribute) | |
33 % | |
34 % --> atomic element | |
35 % - empty cell | |
36 % - empty double | |
37 % - empty char | |
38 % - char | |
39 % - double | |
40 % - logical | |
41 % - java (necessary for timezone) | |
42 % --> <cell> ... | |
43 % --> <object> ... | |
44 % --> <real_data> ... | |
45 % <imag_data> ... | |
46 % | |
47 % </property> | |
48 % OR </cell> | |
49 % | |
50 % ------- real_data --------|-------- imag_data -------- | |
51 % | | |
52 % <real_data>('type'-attribute) | <imag_data> ('type' -attribute) | |
53 % ('shape'-attribute)| ('shape'-attribute) | |
54 % | | |
55 % --> <matrix> ... | --> <matrix> ... | |
56 % --> <vector> ... | --> <vector> ... | |
57 % | | |
58 % </real_data> | </imag_data> | |
59 % | | |
60 % --------- matrix -------------------- vector --------- | |
61 % | | |
62 % <matrix> ('type' -attribute) | <vector> ('type' -attribute) | |
63 % | | |
64 % row vector (double) | column vector (double) | |
65 % | | |
66 % </matrix> | </vector> | |
67 % | |
68 % SYMBOLS: --> Marks a choice between alternatives. | |
69 % ... Indicate that an element may be repeated. | |
70 % | |
71 % VERSION: $Id: xmlread.m,v 1.8 2011/03/28 17:04:27 ingo Exp $ | |
72 % | |
73 % HISTORY: 31-01-2008 Diepholz | |
74 % Creation | |
75 % | |
76 % SEE ALSO: utils.xml.xmlwrite | |
77 % | |
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
79 function values = xmlread(rootNode, obj_name) | |
80 | |
81 % if nargin == 1 | |
82 % node_name = mchar(rootNode.getNodeName); | |
83 % | |
84 % switch node_name | |
85 % case 'ltpda_object' | |
86 % | |
87 % % Get the xml version from the document node | |
88 % % node.getOwnerDocument.item(0).hasAttribute('ltpda_version') | |
89 % if rootNode.hasAttribute('ltpda_version') | |
90 % xml_ver = strtok(mchar(rootNode.getAttribute('ltpda_version'))); | |
91 % else | |
92 % xml_ver = '1.0'; | |
93 % end | |
94 % | |
95 % tbx_ver = strtok(getappdata(0, 'ltpda_version')); | |
96 % | |
97 % % set the application data 'xml_ver' if the xml version is lower than the | |
98 % % toolbox version. | |
99 % % This application data is nedded in the function xml_read_object to | |
100 % % update the object string. | |
101 % if utils.helper.ver2num(xml_ver) < utils.helper.ver2num(tbx_ver) | |
102 % update = xml_ver; | |
103 % else | |
104 % update = ''; | |
105 % end | |
106 % | |
107 % values = xml_read_ltpda_object(rootNode, update); | |
108 % case 'object' | |
109 % values = xml_read_object(rootNode, false); | |
110 % case 'property' | |
111 % values = xml_read_property_cell(rootNode, false); | |
112 % case 'cell' | |
113 % values = xml_read_property_cell(rootNode, false); | |
114 % case 'real_data' | |
115 % values = xml_read_real_imag_data(rootNode); | |
116 % case 'imag_data' | |
117 % values = xml_read_real_imag_data(rootNode); | |
118 % case 'matrix' | |
119 % %%%%% row vector | |
120 % values = sscanf(mchar(child_node.getTextContent), '%g ', [1,inf]); | |
121 % case 'vector' | |
122 % %%%%% column vector | |
123 % values = sscanf(mchar(child_node.getTextContent), '%g '); | |
124 % otherwise | |
125 % %%%%% Search for the next valid node name. | |
126 % for ii = 1:rootNode.getLength | |
127 % item = rootNode.item(ii-1); | |
128 % if item.hasChildNodes | |
129 % values = utils.xml.xmlread(item); | |
130 % end | |
131 % end | |
132 % end | |
133 if nargin >= 1 | |
134 | |
135 values = []; | |
136 valuesShape = []; | |
137 h = history.initObjectWithSize(1,0); | |
138 | |
139 queryNode = rootNode.getElementsByTagName('ltpda_object'); | |
140 | |
141 for ii= 1:queryNode.getLength | |
142 | |
143 LTPDANode = queryNode.item(ii-1); | |
144 if LTPDANode.getNodeType == LTPDANode.ELEMENT_NODE | |
145 | |
146 if LTPDANode.hasAttribute('ltpda_version') | |
147 ltpda_version = strtok(utils.xml.mchar(LTPDANode.getAttribute('ltpda_version'))); | |
148 else | |
149 ltpda_version = '1.0'; | |
150 end | |
151 | |
152 if (utils.helper.ver2num(ltpda_version) > utils.helper.ver2num('2.3')) || ... | |
153 (strcmp(strtok(ltpda_version), '2.3')) | |
154 %%%%%%%%%%%%%%%%%% reading of a new XML file %%%%%%%%%%%%%%%%%% | |
155 | |
156 for jj = 1:LTPDANode.getLength | |
157 | |
158 objNode = LTPDANode.item(jj-1); | |
159 if objNode.getNodeType == objNode.ELEMENT_NODE | |
160 | |
161 className = utils.xml.mchar(objNode.getNodeName()); | |
162 | |
163 if strcmp(className, 'historyRoot') | |
164 | |
165 h = history(objNode, history.initObjectWithSize(1,0)); | |
166 | |
167 else | |
168 valuesShape = utils.xml.getShape(objNode); | |
169 val = feval(className, objNode, h); | |
170 if ~exist('obj_name', 'var') || strcmp(class(val), obj_name) | |
171 values = [values val]; | |
172 else | |
173 error('### Skip the read object because it is from the class [%s] and not from the class [%s].', class(val), obj_name); | |
174 end | |
175 end | |
176 | |
177 end | |
178 end | |
179 values = reshape(values, valuesShape); | |
180 | |
181 else | |
182 %%%%%%%%%%%%%%%%%% reading of a old XML file %%%%%%%%%%%%%%%%%% | |
183 | |
184 for jj = 1:LTPDANode.getLength | |
185 objNode = LTPDANode.item(jj-1); | |
186 if objNode.hasChildNodes | |
187 % Get node name | |
188 node_name = utils.xml.mchar(objNode.getNodeName); | |
189 switch node_name | |
190 case 'object' | |
191 val = xml_read_object(objNode, ltpda_version); | |
192 if isempty(valuesShape), valuesShape = getShape(objNode); end | |
193 if ~exist('obj_name', 'var') || strcmp(class(val), obj_name) | |
194 values = [values val]; | |
195 else | |
196 error('### Skip the read object because it is from the class [%s] and not from the class [%s].', class(val), obj_name); | |
197 end | |
198 otherwise | |
199 end | |
200 end | |
201 end % over all childs | |
202 | |
203 if ~isempty(valuesShape) | |
204 values = reshape(values, valuesShape); | |
205 end | |
206 end | |
207 | |
208 end % LTPDANode.ELEMENT_NODE | |
209 | |
210 end % ii= 1:queryNode.getLength | |
211 | |
212 else | |
213 error('### Invalid command of this function'); | |
214 end | |
215 | |
216 | |
217 end | |
218 | |
219 | |
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
221 % | |
222 % DESCRIPTION: XML_READ_LTPDA_OBJECT Reads a ltoda_object element with the form: | |
223 % | |
224 % <ltpda_object> | |
225 % | |
226 % --> <object> ... | |
227 % --> <cell> ... | |
228 % | |
229 % </ltpda_object> | |
230 % | |
231 % SYMBOLS: --> Marks a choice between alternatives. | |
232 % ... Indicate that an element may be repeated. | |
233 % | |
234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
235 function values = xml_read_ltpda_object(node, update) | |
236 | |
237 values = []; | |
238 for ii = 1:node.getLength | |
239 child_node = node.item(ii-1); | |
240 if child_node.hasChildNodes | |
241 % Get Node name | |
242 node_name = mchar(child_node.getNodeName); | |
243 switch node_name | |
244 case 'object' | |
245 values = [values xml_read_object(child_node, update)]; | |
246 case 'cell' | |
247 values{end+1} = xml_read_property_cell(child_node, update); | |
248 otherwise | |
249 error('### The ''ltpda_object'' element can not contain a [%s] element.', node_name); | |
250 end | |
251 end | |
252 end | |
253 end | |
254 | |
255 | |
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
257 % | |
258 % DESCRIPTION: XML_READ_OBJECT Reads a object element with the form: | |
259 % | |
260 % <object> ('type' - attribute) | |
261 % | |
262 % <property> ... | |
263 % | |
264 % </object> | |
265 % | |
266 % SYMBOLS: ... Indicate that an element may be repeated. | |
267 % | |
268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
269 function obj = xml_read_object(node, update) | |
270 | |
271 obj_type = mchar(node.getAttribute('type')); | |
272 obj = []; | |
273 | |
274 % Set some properties which are stored in the attributes of the 'object' node | |
275 obj = getSpecialObjectAttributes(obj, node, update); | |
276 | |
277 for ii = 1:node.getLength | |
278 child_node = node.item(ii-1); | |
279 %%% Read only the property if the node is a ELEMENT_NODE. | |
280 if child_node.getNodeType == child_node.ELEMENT_NODE | |
281 % Get node name | |
282 node_name = mchar(child_node.getNodeName); | |
283 % get property name from the attribute 'prop_name' | |
284 prop_name = mchar(child_node.getAttribute('prop_name')); | |
285 switch node_name | |
286 case 'property' | |
287 prop_value = xml_read_property_cell(child_node, update); | |
288 | |
289 try | |
290 obj.(prop_name) = prop_value; | |
291 catch | |
292 warning('\n\n### Skip the unknown property [%s] in the object [%s]\n', prop_name, class(obj)); | |
293 disp([char(10) 'Code me up to convert me into the new structure !!!' char(10) ]); | |
294 end | |
295 | |
296 otherwise | |
297 error('### The ''object'' element can not contain a [%s] element.', node_name); | |
298 end | |
299 end | |
300 end | |
301 | |
302 if isempty(update) | |
303 % Make sure that the version we want to update to is far in the future. | |
304 % In other words, we don't do an update if it's not necessary. | |
305 update = '1000000000000000'; | |
306 else | |
307 old_c = {'timeformat', 'pole', 'zero'}; | |
308 new_c = {'', 'pz', 'pz'}; | |
309 | |
310 idx = strmatch(obj_type, char(old_c), 'exact'); | |
311 if ~isempty(idx) | |
312 obj_type = new_c{idx}; | |
313 end | |
314 | |
315 % if ~isempty(obj_type) | |
316 % % Update the structure to the current ltpda_version | |
317 % update_fcn = [obj_type '.update_struct']; | |
318 % obj = feval(update_fcn, obj, update); | |
319 % end | |
320 end | |
321 | |
322 if ~isempty(obj_type) && ~strcmp(obj_type, 'struct') | |
323 obj.class = obj_type; | |
324 obj.tbxver = update; | |
325 obj = feval(obj_type, obj); | |
326 elseif isempty(obj) && strcmp(obj_type, 'struct') | |
327 obj = struct(); | |
328 end | |
329 end | |
330 | |
331 | |
332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
333 % | |
334 % DESCRIPTION: XML_READ_PROPERTY_CELL Reads a property element or a cell element | |
335 % with the form: | |
336 % | |
337 % <property> ('type', 'prop_name' -attributes) | |
338 % OR: <cell> ('type' -attribute) | |
339 % | |
340 % --> atomic element | |
341 % - empty cell | |
342 % - empty double | |
343 % - empty char | |
344 % - char | |
345 % - double | |
346 % - logical | |
347 % - java (necessary for timezone) | |
348 % --> <cell> ... | |
349 % --> <object> ... | |
350 % --> <real_data> ... | |
351 % <imag_data> ... | |
352 % | |
353 % </property> | |
354 % OR: </cell> | |
355 % | |
356 % SYMBOLS: --> Marks a choice between alternatives. | |
357 % ... Indicate that an element may be repeated. | |
358 % | |
359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
360 function prop_value = xml_read_property_cell(node, update) | |
361 | |
362 prop_value = []; | |
363 real_value = []; | |
364 imag_value = []; | |
365 shape = []; | |
366 | |
367 %%% Is the length of the node is equal 1 or zero | |
368 %%% then is the property a atomic element | |
369 if node.getLength == 0 || node.getLength == 1 | |
370 prop_value = xml_read_atomic_element(node); | |
371 return | |
372 end | |
373 | |
374 for ii = 1:node.getLength | |
375 child_node = node.item(ii-1); | |
376 if child_node.getNodeType == child_node.ELEMENT_NODE | |
377 %%% Get the node name | |
378 node_name = mchar(child_node.getNodeName); | |
379 switch node_name | |
380 case 'cell' | |
381 if isempty(shape), shape = getShape(node); end | |
382 prop_value{end+1} = xml_read_property_cell(child_node, update); | |
383 case 'object' | |
384 if isempty(shape), shape = getShape(child_node); end | |
385 prop_value = [prop_value xml_read_object(child_node, update)]; | |
386 case 'real_data' | |
387 real_value = xml_read_real_imag_data(child_node); | |
388 case 'imag_data' | |
389 imag_value = xml_read_real_imag_data(child_node); | |
390 otherwise | |
391 error('### The ''property'' or ''cell'' element can not contain a [%s] element.', node_name); | |
392 end | |
393 | |
394 %%% Is real_value and imag_value filled then return the complex value | |
395 if ~isempty(real_value) && ~isempty(imag_value) | |
396 prop_value = complex(real_value, imag_value); | |
397 %%% Is real_value filled then return the read value | |
398 elseif ~isempty(real_value) | |
399 prop_value = real_value; | |
400 end | |
401 end | |
402 end | |
403 | |
404 %%% Reshape the prop_value if necessary | |
405 if ~isempty(shape) | |
406 prop_value = reshape(prop_value, shape); | |
407 end | |
408 | |
409 end | |
410 | |
411 | |
412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
413 % | |
414 % DESCRIPTION: XML_READ_REAL_IMAG_DATA Reads a real_data element or a | |
415 % imag_data element with the form: | |
416 % | |
417 % <real_data> ('type' -attribute) <imag_data> ('type' -attribute) | |
418 % ('shape'-attribute) ('shape'-attribute) | |
419 % | |
420 % --> <matrix> ... --> <matrix> ... | |
421 % --> <vector> ... --> <vector> ... | |
422 % | |
423 % </real_data> </imag_data> | |
424 % | |
425 % <matrix> ('type' -attribute) <vector> ('type' -attribute) | |
426 % | |
427 % row vector (double) column vector (double) | |
428 % | |
429 % </matrix> </vector> | |
430 % | |
431 % SYMBOLS: --> Marks a choice between alternatives. | |
432 % ... Indicate that an element may be repeated. | |
433 % | |
434 % REMARK: The matrix elements will be read as a row vector. | |
435 % The vector elements will be read as a column vector. | |
436 % | |
437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
438 function value = xml_read_real_imag_data(node) | |
439 | |
440 value = []; | |
441 header_displayed = true; | |
442 | |
443 %%% Get the shape of the matrix/vector | |
444 shape = getShape(node); | |
445 | |
446 % value = zeros(shape); | |
447 % idx = 1; | |
448 | |
449 node_name = ''; | |
450 for ii = 1:node.getLength | |
451 child_node = node.item(ii-1); | |
452 if child_node.hasChildNodes | |
453 %%% Get node name | |
454 node_name = mchar(child_node.getNodeName); | |
455 %%% Get type | |
456 node_type = mchar(child_node.getAttribute('type')); | |
457 switch node_name | |
458 case 'matrix' | |
459 %%% row vector | |
460 if strcmp(node_type, 'sym') | |
461 matrix_row = sym(mchar(child_node.getTextContent)); | |
462 else | |
463 matrix_row = sscanf(mchar(child_node.getTextContent), '%g ', [1,inf]); | |
464 end | |
465 value = [value; matrix_row]; | |
466 % value(idx,:) = matrix_row; | |
467 % idx = idx + 1; | |
468 case 'vector' | |
469 %%% column vector | |
470 if strcmp(node_type, 'sym') | |
471 vector_column = sym(mchar(child_node.getTextContent)); | |
472 else | |
473 vector_column = sscanf(mchar(child_node.getTextContent), '%g '); | |
474 end | |
475 value = [value; vector_column]; | |
476 % value(idx:idx + length(vector_column) - 1) = vector_column; | |
477 % idx = idx + length(vector_column); | |
478 header_displayed = TerminalOutput(node, header_displayed, node_name, length(value)); | |
479 otherwise | |
480 error('### The ''real_data'' or ''imag_data'' element can not contain a [%s] element.', node_name); | |
481 end | |
482 end | |
483 end | |
484 | |
485 if strcmp(node_name, 'matrix') | |
486 header_displayed = true; | |
487 TerminalOutput(node, header_displayed, node_name, size(value,1)); | |
488 end | |
489 value = reshape(value, shape); | |
490 | |
491 end | |
492 | |
493 | |
494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
495 % | |
496 % DESCRIPTION: xml_read_atomic_element Reads a atomic element. | |
497 % This function identify the following types: | |
498 % --> atomic element | |
499 % - empty cell | |
500 % - empty double | |
501 % - empty char | |
502 % - char | |
503 % - double | |
504 % - logical | |
505 % - java (necessary for timezone) | |
506 % | |
507 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
508 function values = xml_read_atomic_element(node) | |
509 | |
510 values = ''; | |
511 | |
512 type = mchar(node.getAttribute('type')); | |
513 switch type | |
514 case {'', 'char'} | |
515 shape = getShape(node); | |
516 if (any(shape==1)) | |
517 values = mchar(node.getTextContent); | |
518 else | |
519 values = reshape(mchar(node.getTextContent), shape); | |
520 end | |
521 values = strrep(values, '<NEW_LINE>', '\n'); | |
522 values = strrep(values, 'CVS_TAG', '$'); | |
523 %%% Special case if 'values' is empty because | |
524 %%% there are more than an one empty char fields. | |
525 %%% For example: '' AND char('', '') AND char('', '', '') AND ... | |
526 if isempty(values) | |
527 if any(shape) | |
528 char_str = 'char('; | |
529 for ii = 1:max(shape) | |
530 char_str = [char_str, ''''', ']; | |
531 end | |
532 char_str = char_str(1:end-2); | |
533 cmd = strcat('values = ', char_str, ');'); | |
534 eval(cmd); | |
535 else | |
536 values = ''; | |
537 end | |
538 end | |
539 | |
540 case {'double', 'uint64', 'uint32', 'int32', 'int64'} | |
541 number = mchar(node.getTextContent); | |
542 | |
543 %%% Special case if 'values' is empty because | |
544 %%% there are more than an one empty double fields. | |
545 %%% For example: [] AND zeros(1,0) AND zeros(0,1) AND zeros(2,0) AND ... | |
546 if isempty(number) | |
547 shape = getShape(node); | |
548 values = zeros(shape); | |
549 else | |
550 values = str2double(number); | |
551 end | |
552 | |
553 % cast to other number type | |
554 if strcmp(type, 'uint64') | |
555 values = uint64(values); | |
556 elseif strcmp(type, 'uint32') | |
557 values = uint32(values); | |
558 elseif strcmp(type, 'int64') | |
559 values = int64(values); | |
560 elseif strcmp(type, 'int32') | |
561 values = int32(values); | |
562 end | |
563 | |
564 case 'sym' | |
565 number = mchar(node.getTextContent); | |
566 | |
567 %%% Special case if 'values' is empty because | |
568 %%% there are more than an one empty double fields. | |
569 %%% For example: [] AND zeros(1,0) AND zeros(0,1) AND zeros(2,0) AND ... | |
570 if isempty(number) | |
571 shape = getShape(node); | |
572 values = sym(shape); | |
573 else | |
574 values = sym(number); | |
575 end | |
576 | |
577 case 'cell' | |
578 cell_str = mchar(node.getTextContent); | |
579 | |
580 %%% Special case if 'values' is empty because | |
581 %%% there are more than an one empty cell fields. | |
582 %%% For example: {} AND cell(1,0) AND cell(0,1) AND cell(2,0) AND ... | |
583 if isempty(cell_str) | |
584 shape = getShape(node); | |
585 values = cell(shape); | |
586 else | |
587 error('### Should not happen because a not empty ''cell'' node have several child nodes.'); | |
588 end | |
589 | |
590 case 'logical' | |
591 cmd = ['logical(' mchar(node.getTextContent) ');']; | |
592 values = eval(cmd); | |
593 | |
594 case 'sun.util.calendar.ZoneInfo' | |
595 values = java.util.TimeZone.getTimeZone(mchar(node.getTextContent)); | |
596 | |
597 otherwise | |
598 | |
599 if any(strcmp(utils.helper.ltpda_non_abstract_classes, type)) | |
600 %%% Special case for reading an object with the size Nx0 or 0xN | |
601 shape = getShape(node); | |
602 cmd = sprintf('%s.initObjectWithSize', type); | |
603 values = feval(cmd, shape(1), shape(2)); | |
604 else | |
605 error('### Unknown type attribute [%s].', type'); | |
606 end | |
607 end | |
608 end | |
609 | |
610 | |
611 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
612 % | |
613 % FUNCTION: shape = getShape(node) | |
614 % | |
615 % INPUTS: node - A DOM node with an attribute 'shape' | |
616 % | |
617 % DESCRIPTION: getShape Helper function to get the shape from the | |
618 % attribute 'shape' as a set of double. | |
619 % | |
620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
621 function shape = getShape(node) | |
622 shape = [NaN NaN]; | |
623 if node.hasAttribute('shape') | |
624 shape_str = mchar(node.getAttribute('shape')); | |
625 x_idx = strfind(shape_str, 'x'); | |
626 shape = [str2double(shape_str(1:x_idx-1)) str2double(shape_str(x_idx+1:end))]; | |
627 end | |
628 end | |
629 | |
630 | |
631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
632 % | |
633 % FUNCTION: obj = getSpecialObjectAttributes(obj, node) | |
634 % | |
635 % INPUTS: obj - a object structure or empty array | |
636 % node - A DOM node with the node name 'object' | |
637 % | |
638 % DESCRIPTION: | |
639 % | |
640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
641 function obj = getSpecialObjectAttributes(obj, node, update) | |
642 | |
643 if strcmp(mchar(node.getNodeName), 'object') | |
644 | |
645 if strcmp(mchar(node.getAttribute('type')), 'time') | |
646 | |
647 % Get attributes for a time object | |
648 % Check if the attribute exist (necessary for backwards compability) | |
649 if (node.hasAttribute('utc')) | |
650 obj.utc_epoch_milli = str2double(mchar(node.getAttribute('utc'))); | |
651 obj.timezone = java.util.TimeZone.getTimeZone(mchar(node.getAttribute('timezone'))); | |
652 obj.timeformat = mchar(node.getAttribute('timeformat')); | |
653 end | |
654 | |
655 elseif strcmp(mchar(node.getAttribute('type')), 'provenance') | |
656 | |
657 % Get attributes for a provenance object | |
658 % Check if the attribute exist (necessary for backwards compability) | |
659 if (node.hasAttribute('info')) | |
660 objStr = mchar(node.getAttribute('info')); | |
661 obj = provenance.setFromEncodedInfo(obj, objStr); | |
662 end | |
663 | |
664 elseif strcmp(mchar(node.getAttribute('type')), 'minfo') | |
665 | |
666 % Get attributes for a minfo object | |
667 % Check if the attribute exist (necessary for backwards compability) | |
668 if (node.hasAttribute('info')) | |
669 objStr = mchar(node.getAttribute('info')); | |
670 obj = minfo.setFromEncodedInfo(obj, objStr); | |
671 end | |
672 | |
673 elseif strcmp(mchar(node.getAttribute('type')), 'param') | |
674 | |
675 % Get attributes for a param object | |
676 % Check if the attribute exist (necessary for backwards compability) | |
677 if (node.hasAttribute('key')) | |
678 obj.key = mchar(node.getAttribute('key')); | |
679 | |
680 for ii = 1:node.getLength | |
681 childNode = node.item(ii-1); | |
682 %%% Read only the property if the node is a ELEMENT_NODE. | |
683 if childNode.getNodeType == childNode.ELEMENT_NODE | |
684 obj.val = xml_read_property_cell(childNode, update); | |
685 end | |
686 end | |
687 end | |
688 | |
689 else | |
690 % Get general attributes. | |
691 if node.hasAttribute('name') | |
692 obj.name = mchar(node.getAttribute('name')); | |
693 end | |
694 if node.hasAttribute('description') | |
695 obj.description = mchar(node.getAttribute('description')); | |
696 end | |
697 if node.hasAttribute('UUID') | |
698 obj.UUID = mchar(node.getAttribute('UUID')); | |
699 end | |
700 if node.hasAttribute('created') | |
701 obj.created = str2double(mchar(node.getAttribute('created'))); | |
702 end | |
703 if node.hasAttribute('proctime') | |
704 obj.proctime = str2double(mchar(node.getAttribute('proctime'))); | |
705 end | |
706 end | |
707 | |
708 | |
709 end | |
710 end | |
711 | |
712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
713 % | |
714 % FUNCTION: header_displayed = TerminalOutput(node, header_displayed, node_name, number) | |
715 % | |
716 % DESCRIPTION: Displays the terminal output. | |
717 % | |
718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
719 function header_displayed = TerminalOutput(node, header_displayed, node_name, number) | |
720 | |
721 import utils.const.* | |
722 | |
723 THRESHOLD_DISP_MATRIX = 10; | |
724 THRESHOLD_DISP_VECTOR = 1000; | |
725 | |
726 showing = false; | |
727 | |
728 if strcmp(node_name, 'matrix') | |
729 if number >= THRESHOLD_DISP_MATRIX | |
730 showing = true; | |
731 add_text = 'matrix lines'; | |
732 end | |
733 else | |
734 if number >= THRESHOLD_DISP_VECTOR | |
735 showing = true; | |
736 add_text = 'data samples'; | |
737 end | |
738 end | |
739 | |
740 if showing == true | |
741 | |
742 parent = node.getParentNode; % The parent node have the 'property name' information | |
743 | |
744 if header_displayed == true | |
745 if parent.hasAttribute('prop_name') | |
746 disp_prop_name = mchar(parent.getAttribute('prop_name')); | |
747 else | |
748 disp_prop_name = 'Unknown Property Name'; | |
749 end | |
750 utils.helper.msg(msg.PROC2, 'Reading property: %s', disp_prop_name); | |
751 | |
752 if strcmp(mchar(node.getNodeName), 'real_data') | |
753 utils.helper.msg(msg.PROC2, 'Reading real data'); | |
754 else | |
755 utils.helper.msg(msg.PROC2, 'Reading imag data'); | |
756 end | |
757 header_displayed = false; | |
758 end | |
759 | |
760 utils.helper.msg(msg.PROC2, 'Read %d %s', number, add_text); | |
761 end | |
762 end | |
763 | |
764 function c = mchar(s) | |
765 c = cell(s); | |
766 c = c{1}; | |
767 end | |
768 | |
769 | |
770 |