1 ## Copyright (C) 2009, 2010 Lukas F. Reichlin
3 ## This file is part of LTI Syncope.
5 ## LTI Syncope is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
10 ## LTI Syncope is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>.
19 ## Display routine for SS objects.
21 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
22 ## Created: September 2009
25 function display (sys)
27 sysname = inputname (1);
28 [inname, outname, tsam] = __lti_data__ (sys.lti);
31 inname = __labels__ (inname, "u");
32 outname = __labels__ (outname, "y");
33 stname = __labels__ (stname, "x");
37 if (! isempty (sys.e))
38 __disp_mat__ (sys.e, [sysname, ".e"], stname, stname);
41 if (! isempty (sys.a))
42 __disp_mat__ (sys.a, [sysname, ".a"], stname, stname);
43 __disp_mat__ (sys.b, [sysname, ".b"], stname, inname);
44 __disp_mat__ (sys.c, [sysname, ".c"], outname, stname);
47 __disp_mat__ (sys.d, [sysname, ".d"], outname, inname);
49 display (sys.lti); # display sampling time
52 disp ("Static gain.");
54 disp ("Continuous-time model.");
56 disp ("Discrete-time model.");
62 function __disp_mat__ (m, mname, rname, cname)
64 MAX_LEN = 12; # max length of row name and column name
65 [mrows, mcols] = size (m);
67 row_name = strjust (strvcat (" ", rname), "left");
68 row_name = row_name(:, 1 : min (MAX_LEN, end));
69 row_name = horzcat (repmat (" ", mrows+1, 3), row_name);
71 mat = cell (1, mcols);
74 cname{k} = cname{k}(:, 1 : min (MAX_LEN, end));
75 acol = vertcat (cname(k), cellstr (deblank (num2str (m(:, k), 4))));
76 mat{k} = strjust (strvcat (acol{:}), "right");
79 lcols = cellfun (@columns, mat);
80 lcols_max = 2 + max (horzcat (lcols, 1));
83 mat{k} = horzcat (repmat (" ", mrows+1, lcols_max-lcols(k)), mat{k});
86 tsize = terminal_size ();
87 dispcols = max (1, floor ((tsize(2) - columns (row_name)) / lcols_max));
88 disprows = max (1, ceil (mcols / dispcols));
93 disp (horzcat (row_name, mat{1+(k-1)*dispcols : min (mcols, k*dispcols)}));