Mercurial > hg > ltpda
comparison m-toolbox/classes/@timespan/display.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % DISPLAY overloads display functionality for timespan objects. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: DISPLAY overloads display functionality for timespan objects. | |
5 % | |
6 % CALL: txt = display(ts) | |
7 % | |
8 % INPUT: ts - timespan object | |
9 % | |
10 % OUTPUT: txt - cell array with strings to display the timespan object | |
11 % | |
12 % <a href="matlab:utils.helper.displayMethodInfo('timespan', 'display')">Parameters Description</a> | |
13 % | |
14 % VERSION: $Id: display.m,v 1.22 2011/04/08 08:56:37 hewitson Exp $ | |
15 % | |
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
17 | |
18 function varargout = display(varargin) | |
19 | |
20 %%% Check if this is a call for parameters | |
21 if utils.helper.isinfocall(varargin{:}) | |
22 varargout{1} = getInfo(varargin{3}); | |
23 return | |
24 end | |
25 | |
26 % Collect all time-objects | |
27 ts = utils.helper.collect_objects(varargin(:), 'timespan'); | |
28 | |
29 txt = {}; | |
30 | |
31 % Print emtpy object | |
32 if isempty(ts) | |
33 hdr = sprintf('------ %s -------', class(ts)); | |
34 ftr(1:length(hdr)) = '-'; | |
35 txt = [txt; {hdr}]; | |
36 txt = [txt; sprintf('empty-object [%d,%d]',size(ts))]; | |
37 txt = [txt; {ftr}]; | |
38 end | |
39 | |
40 for ii = 1:numel(ts) | |
41 t = ts(ii); | |
42 | |
43 b_banner = sprintf('---------- timespan %02d ----------', ii); | |
44 txt{end+1} = b_banner; | |
45 txt{end+1} = ' '; | |
46 | |
47 % Fields to show | |
48 fields = {'name', 'startT', 'endT', 'hist', 'mdlfile', 'description', 'UUID'}; | |
49 max_length = length(fields{1}); | |
50 for jj = 2:length(fields) | |
51 if length(fields{jj}) > max_length | |
52 max_length = length(fields{jj}); | |
53 end | |
54 end | |
55 | |
56 for jj = 1:length(fields) | |
57 field = fields{jj}; | |
58 | |
59 str_field = []; | |
60 str_field(1:max_length-length(field)) = ' '; | |
61 str_field = [str_field field]; | |
62 | |
63 % Display: Number | |
64 if isnumeric(t.(field)) | |
65 txt{end+1} = sprintf ('%s: %s',str_field, num2str(t.(field))); | |
66 | |
67 % Display: Strings | |
68 elseif ischar(t.(field)) | |
69 txt{end+1} = sprintf ('%s: %s',str_field, t.(field)); | |
70 | |
71 % Display: Logicals | |
72 elseif islogical(t.(field)) | |
73 if t.(field) == true | |
74 txt{end+1} = sprintf ('%s: true',str_field); | |
75 else | |
76 txt{end+1} = sprintf ('%s: false',str_field); | |
77 end | |
78 | |
79 % Display: Objects | |
80 elseif isobject(t.(field)) | |
81 if isa(t.(field), 'time') || isa(t.(field), 'timeformat') || isa(t.(field), 'plist') || isa(t.(field), 'provenance') | |
82 txt{end+1} = sprintf ('%s: %s',str_field, char(t.(field))); | |
83 else | |
84 txt{end+1} = sprintf ('%s: %s-object',str_field, class(t.(field))); | |
85 end | |
86 | |
87 elseif iscell(t.(field)) | |
88 txt{end+1} = sprintf('%s: %s',str_field, utils.helper.val2str(t.(field))); | |
89 | |
90 else | |
91 error ('### Please define the output for this property %s', field) | |
92 end | |
93 | |
94 end | |
95 | |
96 | |
97 e_banner(1:length(b_banner)) = '-'; | |
98 txt{end+1} = e_banner; | |
99 | |
100 txt{end+1} = ' '; | |
101 txt{end+1} = ' '; | |
102 | |
103 end | |
104 | |
105 if nargout == 0 | |
106 for ii=1:length(txt) | |
107 disp(txt{ii}); | |
108 end | |
109 else | |
110 varargout{1} = txt; | |
111 end | |
112 | |
113 end | |
114 | |
115 | |
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
117 % Local Functions % | |
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
119 | |
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
121 % | |
122 % FUNCTION: getInfo | |
123 % | |
124 % DESCRIPTION: Get Info Object | |
125 % | |
126 % HISTORY: 11-07-07 M Hewitson | |
127 % Creation. | |
128 % | |
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
130 | |
131 function ii = getInfo(varargin) | |
132 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
133 sets = {}; | |
134 pl = []; | |
135 else | |
136 sets = {'Default'}; | |
137 pl = getDefaultPlist; | |
138 end | |
139 % Build info object | |
140 ii = minfo(mfilename, 'timespan', 'ltpda', utils.const.categories.output, '$Id: display.m,v 1.22 2011/04/08 08:56:37 hewitson Exp $', sets, pl); | |
141 ii.setModifier(false); | |
142 ii.setOutmin(0); | |
143 end | |
144 | |
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
146 % | |
147 % FUNCTION: getDefaultPlist | |
148 % | |
149 % DESCRIPTION: Get Default Plist | |
150 % | |
151 % HISTORY: 11-07-07 M Hewitson | |
152 % Creation. | |
153 % | |
154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
155 | |
156 function plout = getDefaultPlist() | |
157 persistent pl; | |
158 if exist('pl', 'var')==0 || isempty(pl) | |
159 pl = buildplist(); | |
160 end | |
161 plout = pl; | |
162 end | |
163 | |
164 function pl = buildplist() | |
165 pl = plist.EMPTY_PLIST; | |
166 end | |
167 |