Home > classes > @param > display.m

display

PURPOSE ^

DISPLAY display a parameter

SYNOPSIS ^

function txt = display(p, varargin)

DESCRIPTION ^

 DISPLAY display a parameter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: DISPLAY display a parameter

 VERSION: $Id: display.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $

 HISTORY: 30-01-2007 M Hewitson
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function txt = display(p, varargin)
0002 % DISPLAY display a parameter
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: DISPLAY display a parameter
0007 %
0008 % VERSION: $Id: display.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $
0009 %
0010 % HISTORY: 30-01-2007 M Hewitson
0011 %             Creation
0012 %
0013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0014 
0015 VERSION = '$Id: display.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $';
0016 CATEGORY = 'Output';
0017 
0018 % Check if this is a call for parameters
0019 if nargin == 2
0020   if isa(p, 'param') && ischar(varargin{1})
0021     in = char(varargin{1});
0022     if strcmp(in, 'Params')
0023       txt = plist();
0024       return
0025     elseif strcmp(in, 'Version')
0026       txt = VERSION;
0027       return
0028     elseif strcmp(in, 'Category')
0029       txt = CATEGORY;
0030       return
0031     end
0032   end
0033 end
0034 
0035 txt = {};
0036 
0037 for i=1:numel(p)
0038   banner = sprintf('---- param %d ----', i);
0039   txt{end+1} = banner;
0040 
0041   % get key and value
0042   name = get(p(i), 'key');
0043   v    = get(p(i), 'val');
0044 
0045   txt{end+1} = ['key: ' name];
0046 
0047   % convert value for printing
0048 
0049 
0050   %%%%%   Character   %%%%%
0051   if ischar(v)
0052     if length(v) > 45
0053       txt{end+1} = ['val: ''' v(1:45) ' ...'''];
0054     else
0055       txt{end+1} = ['val: ''' v ''''];
0056     end
0057 
0058   %%%%%   Logical   %%%%%
0059   elseif islogical(v)
0060     if v == true
0061       txt{end+1} = 'val: true';
0062     else
0063       txt{end+1} = 'val: false';
0064     end
0065 
0066   %%%%%   Numeric   %%%%%
0067   elseif isnumeric(v)
0068     sval = '';
0069     if size(v,1) == 1 || size(v,2) == 1
0070       for j=1:min(length(v), 10)
0071         sval = [sval sprintf('%g ', v(j))];
0072       end
0073       if length(v) > 10
0074         sval = [sval '...'];
0075       end
0076     elseif isempty(v)
0077       sval = '[]';
0078     else
0079       sval = sprintf('Matrix [%dx%d]', size(v,1), size(v,2));
0080     end
0081     txt{end+1} = ['val: ' sval];
0082 
0083   %%%%%   Symbolic Object   %%%%%
0084   elseif isa(v, 'sym')
0085     sval = char(v);
0086     txt{end+1} = ['val: ' sval];
0087 
0088   %%%%%   Specwin Object   %%%%%
0089   elseif isa(v, 'specwin');
0090     txt{end+1} = ['val: specwin'];
0091     txt = [txt display(v)];
0092 
0093   %%%%%   Provenance Object   %%%%%
0094   elseif isa(v, 'provenance')
0095     txt{end+1} = ['val: ' v.creator '@' v.hostname ' (' v.ip ')'];
0096 
0097   %%%%%   miir and mfir Object   %%%%%
0098   elseif isa(v, 'miir') || isa(v, 'mfir')
0099     txt{end+1} = ['val: ' char(v)];
0100 
0101   %%%%%   time, timespan and timeformat Object   %%%%%
0102   elseif isa(v, 'time') || isa(v, 'timespan') || isa(v, 'timeformat')
0103     txt{end+1} = ['val: ' char(v)];
0104 
0105   %%%%%   ao                              %%%%%
0106   %%%%%   cdata, fsdata, tsdata, xydata   %%%%%
0107   %%%%%   plist, param                    %%%%%
0108   %%%%%   history                         %%%%%
0109   elseif isa(v, 'ao')    || isa(v, 'fsdata')  || isa(v, 'tsdata') || ...
0110          isa(v, 'cdata') || isa(v, 'xydata')  || isa(v, 'plist')  || ...
0111          isa(v, 'param') || isa(v, 'history')
0112     vinfo = whos('v');
0113     txt{end+1} = ['val: ' vinfo.class '-object'];
0114 
0115   %%%%%   pole, zero and pole/zero model Object   %%%%%
0116   elseif isa(v, 'pole') || isa(v, 'zero') || isa(v, 'pzmodel')
0117     sval = '';
0118     for j=1:length(v)
0119       sval = [sval ' ' char(v(j))];
0120     end
0121     txt{end+1} = ['val: ' sval];
0122 
0123   %%%%%   Structures   %%%%%
0124   elseif isstruct(v)
0125 
0126     fields = fieldnames(v);
0127     txt{end+1} = 'val: structure';
0128     for ii=1:length(fields)
0129       field = fields{ii};
0130       if ischar(v.(field))
0131         txt{end+1} = ['     ' field ': ''' v.(field) ''''];
0132       elseif isnumeric(v.(field))
0133         txt{end+1} = ['     ' field ': ' ltpda_mat2str(v.(field))];
0134       elseif isobject(v.(field))
0135         txt{end+1} = ['     ' field ': ' class(v.(field)) '-object'];
0136       else
0137         error('### Do not use a [%s] in a cell array', class(v));
0138       end
0139     end
0140 
0141   %%%%%   Cell   %%%%%
0142   elseif iscell(v)
0143     sval = '';
0144     for ii = 1:length(v)
0145       if ischar(v{ii})
0146         sval = [sval '''' v{ii} ''' '];
0147       elseif isnumeric(v{ii})
0148         sval = [sval '[' ltpda_mat2str(v{ii}) '] '];
0149       elseif isobject(v{ii})
0150         sval = [sval '''' class(v{ii}) ''' '];
0151       else
0152         error('### Do not use a [%s] in a cell array', class(v));
0153       end
0154     end
0155     txt{end+1} = ['val: ' sval];
0156 
0157   %%%%%   JAVA   %%%%%
0158   elseif isjava(v)
0159     txt{end+1} = ['val: ' class(v)];
0160 
0161   else
0162     if isobject(v)
0163       txt{end+1} = sprintf('val: <%s>', class(v));
0164     else
0165       txt{end+1} = sprintf('val: <unknown type>');
0166     end
0167   end
0168 
0169   banner_end(1:length(banner)) = '-';
0170   txt{end+1} = banner_end;
0171 
0172 end
0173 
0174 if nargout == 0
0175   for ii=1:length(txt)
0176     disp(txt{ii});
0177   end
0178 end
0179 
0180 
0181

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003