]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@ss/display.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @ss / display.m
1 ## Copyright (C) 2009, 2010   Lukas F. Reichlin
2 ##
3 ## This file is part of LTI Syncope.
4 ##
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.
9 ##
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.
14 ##
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/>.
17
18 ## -*- texinfo -*-
19 ## Display routine for SS objects.
20
21 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
22 ## Created: September 2009
23 ## Version: 0.2
24
25 function display (sys)
26
27   sysname = inputname (1);
28   [inname, outname, tsam] = __lti_data__ (sys.lti);
29   stname = sys.stname;
30
31   inname = __labels__ (inname, "u");
32   outname = __labels__ (outname, "y");
33   stname = __labels__ (stname, "x");
34
35   disp ("");
36
37   if (! isempty (sys.e))
38     __disp_mat__ (sys.e, [sysname, ".e"], stname, stname);
39   endif
40
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);
45   endif
46
47   __disp_mat__ (sys.d, [sysname, ".d"], outname, inname);
48
49   display (sys.lti);  # display sampling time
50
51   if (tsam == -2)
52     disp ("Static gain.");
53   elseif (tsam == 0)
54     disp ("Continuous-time model.");
55   else
56     disp ("Discrete-time model.");
57   endif
58
59 endfunction
60
61
62 function __disp_mat__ (m, mname, rname, cname)
63
64   MAX_LEN = 12;       # max length of row name and column name
65   [mrows, mcols] = size (m);
66
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);
70
71   mat = cell (1, mcols);
72   
73   for k = 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");
77   endfor
78
79   lcols = cellfun (@columns, mat);
80   lcols_max = 2 + max (horzcat (lcols, 1));
81
82   for k = 1 : mcols
83     mat{k} = horzcat (repmat (" ", mrows+1, lcols_max-lcols(k)), mat{k});
84   endfor
85
86   tsize = terminal_size ();
87   dispcols = max (1, floor ((tsize(2) - columns (row_name)) / lcols_max));
88   disprows = max (1, ceil (mcols / dispcols));
89
90   disp ([mname, " ="]);
91
92   for k = 1 : disprows
93     disp (horzcat (row_name, mat{1+(k-1)*dispcols : min (mcols, k*dispcols)}));
94     disp ("");
95   endfor
96
97 endfunction