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 if isreal(objs)
0177 number_str = sprintf('%.17g ', objs);
0178 else
0179 number_str = num2str(objs, 20);
0180 end
0181 end
0182 content = xml.createTextNode(number_str);
0183 parent.appendChild(content);
0184
0185
0186 elseif (size(objs,1) > 1) && (size(objs,2) > 1)
0187
0188 xml_addmatrix(objs, xml, parent);
0189
0190
0191 elseif (size(objs,1) > 1) || (size(objs,2) > 1)
0192
0193 xml_addvector(objs, xml, parent);
0194
0195 end
0196
0197 else
0198 error('### unknown type [%s]', class(objs));
0199 end
0200 end
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
0227
0228
0229
0230 function xml_addvector(objs, xml, parent)
0231
0232 n_min = getappdata(0, 'xmlsetsize');
0233 header_displayed = true;
0234
0235 shape = sprintf('%dx%d', size(objs,1), size(objs,2));
0236
0237
0238 node_real = xml.createElement('real_data');
0239 node_real.setAttribute('type', 'vector');
0240 node_real.setAttribute('shape', shape);
0241
0242 parent.setAttribute('type', 'vector');
0243 parent.appendChild(node_real);
0244
0245 write_number = real(objs);
0246 sample_num = 0;
0247
0248 while ~isempty(write_number)
0249
0250 n = min(n_min, length(write_number));
0251
0252 sample_num = sample_num + n;
0253 header_displayed = TerminalOutput(parent, header_displayed, true, 'vector', sample_num);
0254
0255 item = xml.createElement('vector');
0256 item.setAttribute('type', class(objs));
0257
0258 if strcmp(class(write_number), 'sym')
0259 number_str = char(write_number(1:n));
0260 else
0261 number_str = ltpda_num2str(write_number(1:n));
0262 end
0263
0264 content = xml.createTextNode(number_str);
0265 node_real.appendChild(item);
0266 item.appendChild(content);
0267
0268 write_number = write_number(n+1:end);
0269 end
0270
0271
0272 if ~isreal(objs)
0273 node_imag = xml.createElement('imag_data');
0274 node_imag.setAttribute('type', 'vector')
0275 node_imag.setAttribute('shape', shape);
0276 parent.appendChild(node_imag);
0277
0278 write_number = imag(objs);
0279 sample_num = 0;
0280
0281 while ~isempty(write_number)
0282 n = min(n_min, length(write_number));
0283
0284 sample_num = sample_num + n;
0285 header_displayed = TerminalOutput(parent, header_displayed, false, 'vector', sample_num);
0286
0287 item = xml.createElement('vector');
0288 item.setAttribute('type', class(objs));
0289
0290 if strcmp(class(write_number), 'sym')
0291 number_str = char(write_number(1:n));
0292 else
0293 number_str = ltpda_num2str(write_number(1:n));
0294 end
0295
0296 content = xml.createTextNode(number_str);
0297 node_imag.appendChild(item);
0298 item.appendChild(content);
0299
0300 write_number = write_number(n+1:end);
0301 end
0302 end
0303 end
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
0331
0332
0333
0334 function xml_addmatrix(objs, xml, parent)
0335
0336 shape = sprintf('%dx%d', size(objs,1), size(objs,2));
0337 header_displayed = true;
0338
0339
0340
0341
0342 node_real = xml.createElement('real_data');
0343 node_real.setAttribute('type', 'matrix');
0344 node_real.setAttribute('shape', shape);
0345
0346 parent.setAttribute('type', 'matrix');
0347 parent.appendChild(node_real);
0348
0349 write_number = real(objs);
0350
0351 for ii = 1:size(write_number,1)
0352
0353 item = xml.createElement('matrix');
0354 item.setAttribute('type', class(objs));
0355
0356 if strcmp(class(write_number), 'sym')
0357 number_str = char(write_number(ii,:));
0358 else
0359 number_str = ltpda_num2str(write_number(ii,:));
0360 end
0361
0362 content = xml.createTextNode(number_str);
0363 node_real.appendChild(item);
0364 item.appendChild(content);
0365 end
0366
0367 TerminalOutput(parent, header_displayed, true, 'matrix', ii);
0368
0369
0370 if ~isreal(objs)
0371 node_imag = xml.createElement('imag_data');
0372 node_imag.setAttribute('type', 'matrix');
0373 node_imag.setAttribute('shape', shape);
0374 parent.appendChild(node_imag);
0375
0376 write_number = imag(objs);
0377
0378 for ii = 1:size(write_number,1)
0379
0380 item = xml.createElement('matrix');
0381 item.setAttribute('type', class(objs));
0382
0383 if strcmp(class(write_number), 'sym')
0384 number_str = char(write_number(ii,:));
0385 else
0386 number_str = ltpda_num2str(write_number(ii,:));
0387 end
0388
0389 content = xml.createTextNode(number_str);
0390 node_imag.appendChild(item);
0391 item.appendChild(content);
0392 end
0393 TerminalOutput(parent, header_displayed, false, 'matrix', ii);
0394 end
0395 end
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405 function header_displayed = TerminalOutput(parent, header_displayed, isreal_num, obj_type, number)
0406
0407 THRESHOLD_DISP_MATRIX = 10;
0408 THRESHOLD_DISP_VECTOR = 1000;
0409
0410 showing = false;
0411
0412 if strcmp(obj_type, 'matrix')
0413 if number >= THRESHOLD_DISP_MATRIX
0414 showing = true;
0415 end
0416 add_text = 'matrix lines';
0417 else
0418 if number >= THRESHOLD_DISP_VECTOR
0419 showing = true;
0420 end
0421 add_text = 'data samples';
0422 end
0423
0424 if showing == true
0425
0426 if header_displayed == true
0427 if parent.hasAttribute('prop_name')
0428 disp_prop_name = char(parent.getAttribute('prop_name'));
0429 else
0430 disp_prop_name = 'Unknown Property Name';
0431 end
0432 disp (sprintf('\n%%%%%%%%%% Write property [%s] %%%%%%%%%%', disp_prop_name));
0433
0434 if isreal_num == true
0435 disp('%%%%% real data %%%%%')
0436 else
0437 disp('%%%%% imaginary data %%%%%')
0438 end
0439 header_displayed = false;
0440 end
0441
0442 disp(sprintf('Write [%d] %s',number, add_text));
0443 end
0444 end
0445