diff m-toolbox/classes/@param/display.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/@param/display.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,83 @@
+% DISPLAY display a parameter
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION: DISPLAY display a parameter
+%              Is called for the parameter object when the semicolon is not used.
+%
+% CALL:        param('a', 1)
+%              txt = display(param('a', 1));
+%
+% VERSION:     $Id: display.m,v 1.54 2011/02/18 16:48:53 ingo Exp $
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function varargout = display(varargin)
+  
+  objs = [varargin{:}];
+  
+  txt = {};
+  
+  for ii = 1:numel(objs)
+    banner = sprintf('---- param %d ----', ii);
+    txt{end+1} = banner;
+    
+    % get key and value
+    name = objs(ii).key;
+    v    = objs(ii).getVal;
+    desc = objs(ii).desc;
+    
+    %%%%%%%%%%%%%%%%%%%%   Add Property 'key'   %%%%%%%%%%%%%%%%%%%%
+    txt{end+1} = ['key:  ' name];
+    
+    %%%%%%%%%%%%%%%%%%%%   Add Property 'val'   %%%%%%%%%%%%%%%%%%%%
+    
+    if isstruct(v)
+      %%%%%%%%%%   Special case: structures
+      txt{end+1} = 'val:  structure';
+      nv = numel(v);
+      for ss = 1:nv
+        if nv > 1, txt{end+1} = sprintf('       --- struct %02d ---', ss); end
+        vs = v(ss);
+        fields = fieldnames(vs);
+        for kk=1:length(fields)
+          field = fields{kk};
+          val   = vs.(field);
+          txt{end+1} = ['       ' field ': ' utils.helper.val2str(val, 60)];
+        end
+      end
+    else
+      %%%%%%%%%%   All other cases
+      txt{end+1} = sprintf('val:  %s', utils.helper.val2str(v, 60));
+    end
+    
+    %%%%%%%%%%%%%%%%%%%%   Add property 'description'   %%%%%%%%%%%%%%%%%%%%
+    %%% Display the description only if it is not empty
+    if ~isempty(desc)
+      
+      if iscell(desc)
+        txt{end+1} = ['desc: ' desc(1,:)];
+        for kk = 2:size(desc,1)
+          txt{end+1} = ['      ' desc(kk,:)];
+        end
+      else
+        txt{end+1} = ['desc: ' desc];
+      end
+    end
+    
+    banner_end(1:length(banner)) = '-';
+    txt{end+1} = banner_end;
+    
+  end
+  
+  %%% Prepare output
+  if nargout == 0
+    for ii=1:length(txt)
+      disp(sprintf(txt{ii}));
+    end
+  elseif nargout == 1
+    varargout{1} = txt;
+  end
+  
+end
+
+