2 % @brief Prints comprehensive information about a NetworkStruct
object
4 % @author LINE Development Team
8 % @brief Prints comprehensive information about a NetworkStruct
object
11 % This function displays all fields, matrices, lists, and maps in a formatted
12 % manner useful
for debugging and inspection of network structures.
21 % <tr><th>Name<th>Description
22 % <tr><td>sn<td>Network structure to inspect
27% Suppress warnings about
struct on objects
28warning(
'off',
'MATLAB:structOnObject');
31fprintf(
'nstations: %d\n', sn.nstations);
32fprintf(
'nstateful: %d\n', sn.nstateful);
33fprintf(
'nnodes: %d\n', sn.nnodes);
34fprintf(
'nclasses: %d\n', sn.nclasses);
35fprintf(
'nclosedjobs: %d\n', sn.nclosedjobs);
36fprintf(
'nchains: %d\n', sn.nchains);
39printMatrix(
'refstat', sn.refstat);
40printMatrix(
'njobs', sn.njobs);
41printMatrix(
'nservers', sn.nservers);
42printMatrix(
'connmatrix', sn.connmatrix);
43printMatrix(
'scv', sn.scv);
44printMatrix(
'isstation', sn.isstation);
45printMatrix(
'isstateful', sn.isstateful);
46printMatrix(
'isstatedep', sn.isstatedep);
47printMatrix(
'nodeToStateful', sn.nodeToStateful);
48printMatrix(
'nodeToStation', sn.nodeToStation);
49printMatrix(
'stationToNode', sn.stationToNode);
50printMatrix(
'stationToStateful', sn.stationToStateful);
51printMatrix(
'statefulToStation', sn.statefulToStation);
52printMatrix(
'statefulToNode', sn.statefulToNode);
53printMatrix(
'rates', sn.rates);
54printMatrix(
'classprio', sn.classprio);
55printMatrix(
'phases', sn.phases);
56printMatrix(
'phasessz', sn.phasessz);
57printMatrix(
'phaseshift', sn.phaseshift);
58printMatrix(
'schedparam', sn.schedparam);
59printMatrix(
'chains', sn.chains);
60printMatrix(
'rt', sn.rt);
61printMatrix(
'nvars', sn.nvars);
62printMatrix(
'rtnodes', sn.rtnodes);
63printMatrix(
'csmask', sn.csmask);
64printMatrix(
'isslc', sn.isslc);
65printMatrix(
'cap', sn.cap);
66printMatrix(
'classcap', sn.classcap);
67printMatrix(
'refclass', sn.refclass);
68printMatrix(
'lldscaling', sn.lldscaling);
69printMatrix(
'fj', sn.fj);
71% List fields with content
72printNodeTypeList(
'nodetype', sn.nodetype);
73if isfield(sn,
'classnames')
74 if iscell(sn.classnames)
75 printList('classnames', sn.classnames);
77 % Handle single
string classname
78 fprintf('classnames: ["%s"]\n', sn.classnames);
81if isfield(sn, 'nodenames')
82 printList('nodenames', sn.nodenames);
85% Map fields with detailed contents
86printMapIfExists(sn, 'rtorig');
87%printMapIfExists(sn, 'lst');
88printMapIfExists(sn, 'state');
89printMapIfExists(sn, 'stateprior');
90printMapIfExists(sn, 'space');
91printMapIfExists(sn, 'routing');
92printMapIfExists(sn, 'procid');
93printMapIfExists(sn, 'mu');
94printMapIfExists(sn, 'phi');
95printMapIfExists(sn, 'proc');
96printMapIfExists(sn, 'pie');
97printMapIfExists(sn, 'sched');
98printMapIfExists(sn, 'inchain');
99printMapIfExists(sn, '
visits');
101printMapIfExists(sn, 'droprule');
102printMapIfExists(sn, 'nodeparam');
103% Special handling for sync field to avoid duplicate printing
104if isfield(sn, 'sync')
108 % sync
is a cell array of sync objects
110 for i = 1:length(value)
114 fprintf('%d:
', i-1); % 0-based index
117 if isstruct(syncObj) && isfield(syncObj, 'active
') && isfield(syncObj, 'passive
')
119 % Print active events with indices
120 fprintf('"active": {
');
121 if iscell(syncObj.active)
122 for j = 1:length(syncObj.active)
126 fprintf('%d:
', j-1); % 0-based index
127 printValue(syncObj.active{j});
131 printValue(syncObj.active);
135 % Print passive events with indices
136 fprintf(',
"passive": {
');
137 if iscell(syncObj.passive)
138 for j = 1:length(syncObj.passive)
142 fprintf('%d:
', j-1); % 0-based index
143 printValue(syncObj.passive{j});
147 printValue(syncObj.passive);
156 elseif isstruct(value)
157 % Check if it's a
map of sync objects
158 fields = fieldnames(value);
161 for i = 1:length(fields)
166 % Handle numeric keys like x0, x1
167 if regexp(key,
'^x\d+$')
168 fprintf('%s', key(2:end));
170 fprintf('"%s"', key);
174 syncObj = value.(key);
175 if isstruct(syncObj) && isfield(syncObj, 'active') && isfield(syncObj, 'passive')
177 % Print active events with indices
178 fprintf('"active": {
');
179 if iscell(syncObj.active)
180 for j = 1:length(syncObj.active)
184 fprintf('%d:
', j-1); % 0-based index
185 printValue(syncObj.active{j});
189 printValue(syncObj.active);
193 % Print passive events with indices
194 fprintf(',
"passive": {
');
195 if iscell(syncObj.passive)
196 for j = 1:length(syncObj.passive)
200 fprintf('%d:
', j-1); % 0-based index
201 printValue(syncObj.passive{j});
205 printValue(syncObj.passive);
222 % Field doesn't exist, skip
224printMapIfExists(sn,
'gsync');
225printMapIfExists(sn,
'cdscaling');
228warning(
'on',
'MATLAB:structOnObject');
232function matStr = printMatrixCompact(matrix)
233% Helper function to print matrix in compact format
for maps
240[numRows, numCols] = size(matrix);
249 value = matrix(i, j);
250 % Check
if matrix contains only integers or
if individual value
is integer
251 if (isnumeric(matrix) && all(matrix(:) == floor(matrix(:))) && all(~isinf(matrix(:)))) || ...
252 (value == floor(value) && ~isinf(value))
253 sb = [sb num2str(round(value))];
255 sb = [sb num2str(value)];
263function printNodeTypeList(name, nodeTypes)
264% Helper function to print nodetype array with proper formatting
265fprintf(
'%s: ', name);
270 for i = 1:length(nodeTypes)
274 fprintf(
'%s', NodeType.toText(nodeTypes(i)));
280function printList(name, list)
281% Helper function to print lists with proper formatting
282fprintf(
'%s: ', name);
287 for i = 1:length(list)
291 if ischar(list{i}) || isstring(list{i})
292 fprintf(
'"%s"',
char(list{i}));
294 fprintf(
'%s', mat2str(list{i}));
298elseif isnumeric(list)
299 % Handle numeric arrays
300 fprintf(
'%s\n', printMatrixCompact(list));
303 fprintf(
'%s\n', mat2str(list));
307function printMatrix(name, matrix)
308% Helper function to print matrix with all values
310 fprintf(
'%s: []\n', name);
311elseif isnumeric(matrix) && all(isnan(matrix(:)))
312 fprintf(
'%s: null\n', name);
314 fprintf(
'%s: %s\n', name, printMatrixCompact(matrix));
318function printMapIfExists(sn, fieldName)
319% Helper function to print fields only
if they exist
320if isfield(sn, fieldName)
321 value = sn.(fieldName);
323 printMapContents(fieldName, value);
325 printCellContents(fieldName, value);
327 % For other types, use printMatrix
328 printMatrix(fieldName, value);
333function printCellContents(name, cellArray)
334% Helper function to print cell array contents
335fprintf(
'%s: ', name);
339 % Check
if this is a single-element cell array containing a matrix
340 if numel(cellArray) == 1 && isnumeric(cellArray{1})
341 % Just print the matrix directly without extra brackets
342 fprintf(
'%s\n', printMatrixCompact(cellArray{1}));
346 % Check
if this is a
map-like cell array
347 if numel(cellArray) > 0 && isstruct(cellArray{1})
349 printMapContents(name, cellArray{1});
353 % Special handling
for certain fields that are
map-like
354 if strcmp(name, 'state') || strcmp(name, 'stateprior') || strcmp(name, 'space') || ...
355 strcmp(name, 'mu') || strcmp(name, 'phi') || strcmp(name, 'pie')
356 % These fields use station names as keys
358 % Assume we have access to station names through evalin
360 nodenames = evalin('caller
', 'sn.nodenames
');
361 for i = 1:numel(cellArray)
365 if i <= length(nodenames)
366 fprintf('"%s":
', nodenames{i});
368 printValue(cellArray{i});
371 % Fall back to simple array printing
372 for i = 1:numel(cellArray)
376 printValue(cellArray{i});
381 % Regular cell array - use [] for arrays
383 for i = 1:numel(cellArray)
387 printValue(cellArray{i});
394function printMapContents(name, mapStruct)
395% Helper function to print map contents with detailed structure
396if isempty(mapStruct) || ~exist('mapStruct
', 'var
')
398 fprintf('%s: null\n
', name);
405if ~isstruct(mapStruct)
407 fprintf('%s: null\n
', name);
414fields = fieldnames(mapStruct);
417 fprintf('%s: {}\n
', name);
425 fprintf('%s: {
', name);
430for i = 1:length(fields)
436 % Print key - handle different key types like the Kotlin version
438 % Check if key is numeric (like x0, x1, etc.)
439 if regexp(key, '^x\d+$')
440 % Extract the numeric part
441 fprintf('%s', key(2:end));
443 fprintf(
'"%s"', key);
445 fprintf(
'"%s"',
char(
string(key)));
451 value = mapStruct.(key);
457function printValue(value)
458% Helper function to print individual values with appropriate formatting
461elseif isa(value,
'jline.lang.Event') || (isjava(value) && contains(
class(value),
'Event'))
462 % Handle Java Event objects
466 % Try to print each field
468 nodeVal = value.getNode();
469 fprintf(
'"node": %d', nodeVal);
476 eventVal = value.getEvent();
480 fprintf('"event":
');
482 fprintf('%d
', eventVal.getId());
484 fprintf('"%s"', char(eventVal.toString()));
492 classVal = value.getJobClass();
496 fprintf(
'"class": %d', classVal);
501 probVal = value.getProb();
509 fprintf(
'%g', probVal);
517 stateVal = value.getState();
521 fprintf(
'"state": ');
522 if isempty(stateVal) || (isa(stateVal,
'jline.util.matrix.Matrix') && stateVal.isEmpty())
525 printValue(stateVal);
549 jobVal = value.getJob();
557 fprintf(
'%g', jobVal);
564 % If nothing was printed, show it
's an Event
570elseif isstruct(value)
571 fields = fieldnames(value);
573 % Check if this might be a Java object that appears as empty struct
574 className = class(value);
575 if contains(className, 'Event
')
576 fprintf('{<Event
object - fields not accessible>}');
582 for i = 1:length(fields)
586 fprintf(
'"%s": ', fields{i});
587 printValue(value.(fields{i}));
591elseif isnumeric(value)
593 fprintf(
'%s', printMatrixCompact(value));
595 if value == floor(value) && ~isinf(value)
596 fprintf(
'%d', round(value));
598 fprintf(
'%g', value);
601elseif ischar(value) || isstring(value)
602 fprintf(
'"%s"',
char(value));
603elseif islogical(value)
610 % Check
if this is a nested cell array (like proc field)
611 if numel(value) > 0 && iscell(value{1})
612 % Handle nested cell array as indexed
map
614 for i = 1:numel(value)
618 fprintf(
'[%d]: ', i-1); % Use 0-based indexing for consistency with Java
619 printValue(value{i});
625 for i = 1:length(value)
629 printValue(value{i});
633elseif isa(value,
'function_handle')
634 % Display function handles similar to Java lambda notation
635 funcStr = func2str(value);
636 if contains(funcStr,
'@')
637 funcStr = strrep(funcStr, '@', '');
639 fprintf('%s', funcStr);
641 % Handle objects and other types
643 % Check if it's a Sync
object
644 if isa(value, 'Sync')
646 fprintf('"active":
');
647 printValue(value.active);
648 fprintf(',
"passive":
');
649 printValue(value.passive);
652 str = char(string(value));
653 % Check if this is a sync string that needs special handling
654 if contains(str, 'sync:
')
655 % This is likely the sync field being printed as a string
656 % Extract the content after "sync:"
657 syncContent = strtrim(extractAfter(str, 'sync:
'));
658 fprintf('%s
', syncContent);
659 elseif contains(str, 'x
') && contains(str, ' ')
660 % Clean up MATLAB object notation (e.g., 1x1 ClosedClass)
661 parts = split(str, ' ');
662 if length(parts) >= 2
663 fprintf('%s
', parts{end});
672 % If conversion fails, just display the class name
673 fprintf('<%s>
', class(value));