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

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