0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 function ltpda_xmlwrite(objs, xml, parent, property_name)
0085
0086
0087 if ~isempty(property_name)
0088 shape = sprintf('%dx%d', size(objs,1), size(objs,2));
0089
0090 prop_node = xml.createElement('property');
0091 prop_node.setAttribute('prop_name', property_name);
0092 prop_node.setAttribute('shape', shape);
0093 prop_node.setAttribute('type', class(objs));
0094 parent.appendChild(prop_node);
0095 parent = prop_node;
0096 end
0097
0098
0099 if (isobject(objs) || isstruct(objs)) && ~isa(objs, 'sym')
0100
0101 for ii = 1:numel(objs)
0102
0103 obj = objs(ii);
0104
0105 shape = sprintf('%dx%d', size(objs,1), size(objs,2));
0106
0107 obj_node = xml.createElement('object');
0108 obj_node.setAttribute('type', class(obj));
0109 obj_node.setAttribute('shape', shape);
0110
0111 parent.appendChild(obj_node);
0112
0113 fields = fieldnames(obj);
0114
0115 for jj = 1:length(fields)
0116 field = fields{jj};
0117 ltpda_xmlwrite(obj.(field), xml, obj_node, field);
0118 end
0119 end
0120
0121
0122 elseif isjava(objs)
0123 if strcmp(class(objs), 'sun.util.calendar.ZoneInfo')
0124 content = xml.createTextNode(char(objs.getID));
0125 parent.appendChild(content);
0126 else
0127 error('### Unknown Java');
0128 end
0129
0130
0131 elseif iscell(objs)
0132
0133 for ii = 1:numel(objs)
0134
0135 obj = objs{ii};
0136
0137 shape = sprintf('%dx%d', size(obj,1), size(obj,2));
0138
0139 cell_node = xml.createElement('cell');
0140 cell_node.setAttribute('type', class(obj));
0141 cell_node.setAttribute('prop_name', property_name);
0142 cell_node.setAttribute('shape', shape);
0143
0144 parent.appendChild(cell_node);
0145
0146 ltpda_xmlwrite(obj, xml, cell_node, '');
0147
0148 end
0149
0150
0151 elseif ischar(objs)
0152 content = xml.createTextNode(objs);
0153 parent.appendChild(content);
0154
0155
0156 elseif islogical(objs)
0157 if numel(objs) == 1
0158 if objs
0159 content = xml.createTextNode('true');
0160 else
0161 content = xml.createTextNode('false');
0162 end
0163 parent.appendChild(content);
0164 else
0165 error ('### At the moment is only one logical allowed. The size is [%dx%d]', size(objs,1), size(objs,2));
0166 end
0167
0168
0169 elseif isnumeric(objs) || isa(objs, 'sym')
0170
0171
0172 if (size(objs,1) == 1) && (size(objs,2) == 1)
0173 if strcmp(class(objs), 'sym')
0174 number_str = char(objs, 20);
0175 else
0176 number_str = num2str(objs, 20);
0177 end
0178 content = xml.createTextNode(number_str);
0179 parent.appendChild(content);
0180
0181
0182 elseif (size(objs,1) > 1) && (size(objs,2) > 1)
0183
0184 xml_addmatrix(objs, xml, parent);
0185
0186
0187 elseif (size(objs,1) > 1) || (size(objs,2) > 1)
0188
0189 xml_addvector(objs, xml, parent);
0190
0191 end
0192
0193 else
0194 error('### unknown type [%s]', class(objs));
0195 end
0196 end
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226 function xml_addvector(objs, xml, parent)
0227
0228 n_min = getappdata(0, 'xmlsetsize');
0229 header_displayed = true;
0230
0231 shape = sprintf('%dx%d', size(objs,1), size(objs,2));
0232
0233
0234 node_real = xml.createElement('real_data');
0235 node_real.setAttribute('type', 'vector');
0236 node_real.setAttribute('shape', shape);
0237
0238 parent.setAttribute('type', 'vector');
0239 parent.appendChild(node_real);
0240
0241 write_number = real(objs);
0242 sample_num = 0;
0243
0244 while ~isempty(write_number)
0245
0246 n = min(n_min, length(write_number));
0247
0248 sample_num = sample_num + n;
0249 header_displayed = TerminalOutput(parent, header_displayed, true, 'vector', sample_num);
0250
0251 item = xml.createElement('vector');
0252 item.setAttribute('type', class(objs));
0253
0254 if strcmp(class(write_number), 'sym')
0255 number_str = char(write_number(1:n));
0256 else
0257 number_str = ltpda_num2str(write_number(1:n));
0258 end
0259
0260 content = xml.createTextNode(number_str);
0261 node_real.appendChild(item);
0262 item.appendChild(content);
0263
0264 write_number = write_number(n+1:end);
0265 end
0266
0267
0268 if ~isreal(objs)
0269 node_imag = xml.createElement('imag_data');
0270 node_imag.setAttribute('type', 'vector')
0271 node_imag.setAttribute('shape', shape);
0272 parent.appendChild(node_imag);
0273
0274 write_number = imag(objs);
0275 sample_num = 0;
0276
0277 while ~isempty(write_number)
0278 n = min(n_min, length(write_number));
0279
0280 sample_num = sample_num + n;
0281 header_displayed = TerminalOutput(parent, header_displayed, false, 'vector', sample_num);
0282
0283 item = xml.createElement('vector');
0284 item.setAttribute('type', class(objs));
0285
0286 if strcmp(class(write_number), 'sym')
0287 number_str = char(write_number(1:n));
0288 else
0289 number_str = ltpda_num2str(write_number(1:n));
0290 end
0291
0292 content = xml.createTextNode(number_str);
0293 node_imag.appendChild(item);
0294 item.appendChild(content);
0295
0296 write_number = write_number(n+1:end);
0297 end
0298 end
0299 end
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330 function xml_addmatrix(objs, xml, parent)
0331
0332 shape = sprintf('%dx%d', size(objs,1), size(objs,2));
0333 header_displayed = true;
0334
0335
0336
0337
0338 node_real = xml.createElement('real_data');
0339 node_real.setAttribute('type', 'matrix');
0340 node_real.setAttribute('shape', shape);
0341
0342 parent.setAttribute('type', 'matrix');
0343 parent.appendChild(node_real);
0344
0345 write_number = real(objs);
0346
0347 for ii = 1:size(write_number,1)
0348
0349 item = xml.createElement('matrix');
0350 item.setAttribute('type', class(objs));
0351
0352 if strcmp(class(write_number), 'sym')
0353 number_str = char(write_number(ii,:));
0354 else
0355 number_str = ltpda_num2str(write_number(ii,:));
0356 end
0357
0358 content = xml.createTextNode(number_str);
0359 node_real.appendChild(item);
0360 item.appendChild(content);
0361 end
0362
0363 TerminalOutput(parent, header_displayed, true, 'matrix', ii);
0364
0365
0366 if ~isreal(objs)
0367 node_imag = xml.createElement('imag_data');
0368 node_imag.setAttribute('type', 'matrix');
0369 node_imag.setAttribute('shape', shape);
0370 parent.appendChild(node_imag);
0371
0372 write_number = imag(objs);
0373
0374 for ii = 1:size(write_number,1)
0375
0376 item = xml.createElement('matrix');
0377 item.setAttribute('type', class(objs));
0378
0379 if strcmp(class(write_number), 'sym')
0380 number_str = char(write_number(ii,:));
0381 else
0382 number_str = ltpda_num2str(write_number(ii,:));
0383 end
0384
0385 content = xml.createTextNode(number_str);
0386 node_imag.appendChild(item);
0387 item.appendChild(content);
0388 end
0389 TerminalOutput(parent, header_displayed, false, 'matrix', ii);
0390 end
0391 end
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401 function header_displayed = TerminalOutput(parent, header_displayed, isreal_num, obj_type, number)
0402
0403 THRESHOLD_DISP_MATRIX = 10;
0404 THRESHOLD_DISP_VECTOR = 1000;
0405
0406 showing = false;
0407
0408 if strcmp(obj_type, 'matrix')
0409 if number >= THRESHOLD_DISP_MATRIX
0410 showing = true;
0411 end
0412 add_text = 'matrix lines';
0413 else
0414 if number >= THRESHOLD_DISP_VECTOR
0415 showing = true;
0416 end
0417 add_text = 'data samples';
0418 end
0419
0420 if showing == true
0421
0422 if header_displayed == true
0423 if parent.hasAttribute('prop_name')
0424 disp_prop_name = char(parent.getAttribute('prop_name'));
0425 else
0426 disp_prop_name = 'Unknown Property Name';
0427 end
0428 disp (sprintf('\n%%%%%%%%%% Write property [%s] %%%%%%%%%%', disp_prop_name));
0429
0430 if isreal_num == true
0431 disp('%%%%% real data %%%%%')
0432 else
0433 disp('%%%%% imaginary data %%%%%')
0434 end
0435 header_displayed = false;
0436 end
0437
0438 disp(sprintf('Write [%d] %s',number, add_text));
0439 end
0440 end
0441