0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 function attachNumberToDom(number, dom, parent)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % Store the original shape
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 parent.setAttribute('shape', sprintf('%dx%d', size(number)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 parent.setAttribute('type', class(number));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 if isempty(number)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 %%%%% Nothing to do
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % For example: <parent shape="8x0"/>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 elseif numel(number) == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 %%%%% Single number
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % For example: <parent shape="1x1">1</parent>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % <parent shape="1x1">1+3i</parent>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 if isreal(number)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 numberStr = sprintf('%.17g', number);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 numberStr = ['[', num2str(number, 20), ']'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 content = dom.createTextNode(numberStr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 parent.appendChild(content);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 elseif isvector(number) && ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 isreal(number) && ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 numel(number) <= utils.xml.MAX_DOUBLE_IN_ROW
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 %%%%% Real vector which is not longer than 50000 values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 % For example: <parent shape="1x10">1 2 3 4 5 6 7 8 9 0</parent>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 content = dom.createTextNode(strtrim(utils.xml.num2str(number)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 parent.appendChild(content);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 elseif isvector(number) && ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 ~isreal(number) && ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 numel(number) <= utils.xml.MAX_IMAG_IN_ROW
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 %%%%% imaginary vector which is not longer than 1000 values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 % For example: <parent shape="1x10">[1+1i 2+1i 3 4-4i ...]</parent>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 content = dom.createTextNode(strtrim(utils.xml.mat2str(number)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 parent.appendChild(content);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 elseif (size(number,1) > 1) && ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 (size(number,2) > 1) && ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 isreal(number) && numel(number) <= utils.xml.MAX_NUM_IN_MATRIX
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 %%%%% Real matrix which have not more than 2500 values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 % For example: <parent shape="2x3">[1 2 3; 4 5 6]</parent>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 content = dom.createTextNode(strtrim(utils.xml.mat2str(number)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 parent.appendChild(content);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 elseif isvector(number)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 %%%%% General vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 % For example: <parent>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 % <realData type="vector">
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 % <vector> 1 2 3 4 5 6 7 8 9 10 ...</vector>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 % <vector>11 12 13 14 15 16 17 18 19 20 ...</vector>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 % </realData>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 % <imagData type="vector">
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 % <vector> 1 2 3 4 5 6 7 8 9 10 ...</vector>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 % <vector>11 12 13 14 15 16 17 18 19 20 ...</vector>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 % </imagData>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 % </parent>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 utils.xml.attachVectorToDom(number, dom, parent);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 elseif (size(number,1) > 1) && (size(number,2) > 1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 %%%%% General matrix
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 % For example: <parent>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 % <realData type="matrix">
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 % <matrix> 1 2 3 4 5 6 7 8 9 10 ...</matrix>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 % <matrix>11 12 13 14 15 16 17 18 19 20 ...</matrix>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 % ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 % </realData>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 % <imagData type="matrix">
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 % <matrix> 1 2 3 4 5 6 7 8 9 10 ...</matrix>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 % <matrix>11 12 13 14 15 16 17 18 19 20 ...</matrix>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 % ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 % </imagData>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 % </parent>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 utils.xml.attachMatrixToDom(number, dom, parent);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 error('### Should not happen. Size of the input object %dx%d', size(number))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92
|