Home > classes > @time > display.m

display

PURPOSE ^

DISPLAY overloads display functionality for time objects.

SYNOPSIS ^

function txt = display(tt, varargin)

DESCRIPTION ^

 DISPLAY overloads display functionality for time objects.

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

 DESCRIPTION: DISPLAY overloads display functionality for time objects.

 CALL:        txt  = display(time)

 INPUT:       time - time object

 OUTPUT:      txt  - cell array with strings to display the time object

 VERSION:     $Id: display.m,v 1.8 2008/01/14 20:03:52 ingo Exp $

 HISTORY:     23-07-2007 Diepholz
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function txt = display(tt, varargin)
0002 % DISPLAY overloads display functionality for time objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: DISPLAY overloads display functionality for time objects.
0007 %
0008 % CALL:        txt  = display(time)
0009 %
0010 % INPUT:       time - time object
0011 %
0012 % OUTPUT:      txt  - cell array with strings to display the time object
0013 %
0014 % VERSION:     $Id: display.m,v 1.8 2008/01/14 20:03:52 ingo Exp $
0015 %
0016 % HISTORY:     23-07-2007 Diepholz
0017 %                 Creation
0018 %
0019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0020 
0021 VERSION  = '$Id: display.m,v 1.8 2008/01/14 20:03:52 ingo Exp $';
0022 
0023 % Check if this is a call for parameters
0024 if nargin == 2
0025   if isa(tt, 'time') && ischar(varargin{1})
0026     in = char(varargin{1});
0027     if strcmp(in, 'Params')
0028       txt = plist;
0029       return
0030     elseif strcmp(in, 'Version')
0031       txt = VERSION;
0032       return
0033     end
0034   end
0035 end
0036 
0037 txt = {};
0038 
0039 for ii = 1:numel(tt)
0040   t = tt(ii);
0041 
0042   b_banner = sprintf('---------- time %02d ----------', ii);
0043   txt{end+1} = b_banner;
0044   txt{end+1} = ' ';
0045 
0046   fields = fieldnames(t);
0047   max_length = length(fields{1});
0048   for jj = 2:length(fields)
0049     if length(fields{jj}) > max_length
0050       max_length = length(fields{jj});
0051     end
0052   end
0053 
0054   for jj = 1:length(fields)
0055     field = fields{jj};
0056 
0057     str_field = [];
0058     str_field(1:max_length-length(field)) = ' ';
0059     str_field = [field str_field];
0060 
0061     % Add before the fields 'created' and 'version' a blank line
0062     if strcmp(field, 'created')
0063       txt{end+1} = ' ';
0064     end
0065 
0066     % Display: Number
0067     if isnumeric(t.(field))
0068       txt{end+1} = sprintf ('%s: %s',str_field, num2str(t.(field)));
0069 
0070     % Display: Strings
0071     elseif ischar(t.(field))
0072       txt{end+1} = sprintf ('%s: %s',str_field, t.(field));
0073 
0074     % Display: Logicals
0075     elseif islogical(t.(field))
0076       if t.(field) == true
0077         txt{end+1} = sprintf ('%s: true',str_field);
0078       else
0079         txt{end+1} = sprintf ('%s: false',str_field);
0080       end
0081 
0082     % Display: Objects
0083     elseif isobject(t.(field))
0084       if isa(t.(field), 'timeformat')
0085         txt{end+1} = sprintf ('%s: %s',str_field, char(t.(field)));
0086       else
0087         txt{end+1} = sprintf ('%s: %s class',str_field, class(t.(field)));
0088       end
0089 
0090     % Display: Java Objects
0091     elseif isjava(t.(field))
0092       if strcmp(class(t.(field)), 'sun.util.calendar.ZoneInfo')
0093         EE = java.text.SimpleDateFormat('Z');
0094         EE.setTimeZone(t.(field))
0095         zone_id = t.(field).getID;
0096         if strcmp(zone_id, 'UTC')
0097           txt{end+1} = sprintf ('%s: %s',str_field, char(t.(field).getID));
0098         else
0099           txt{end+1} = sprintf ('%s: %s (UTC%s)',str_field, char(t.(field).getID), char(EE.format(t.utc_epoch_milli)));
0100         end
0101       else
0102         error ('### Unknown java class %s', class(t.(field)))
0103       end
0104 
0105     else
0106       error ('### Please define the output for this property %s', field)
0107     end
0108 
0109   end
0110 
0111 
0112   e_banner(1:length(b_banner)) = '-';
0113   txt{end+1} = e_banner;
0114 
0115   txt{end+1} = ' ';
0116   txt{end+1} = ' ';
0117 
0118 end
0119 
0120 if nargout == 0
0121   for ii=1:length(txt)
0122     disp(txt{ii});
0123   end
0124 end
0125 
0126

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003