Home > classes > @timeformat > set.m

set

PURPOSE ^

SET set timeformat properties.

SYNOPSIS ^

function tf = set(tf, varargin)

DESCRIPTION ^

 SET set timeformat properties.

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

 DESCRIPTION: SET set timeformat properties.

 CALL:        tf = set(tf, 'property', 'value');
              tf = set(tf, 'property', 'value', 'direct');

 EXAMPLES:    tt = set(tt, 'format_str',         'yyyy.dd.mm HH:MM:SS AM');
              tt = set(tt, 'format_nr',           0);
              tt = set(tt, 'default_matlab_str', 'yyyy-mm-dd HH:MM:SS');
              tt = set(tt, 'default_matlab_nr',   31);
              tt = set(tt, 'default_java_str',   'yyyy-MM-dd HH:mm:ss');

 VERSION:     $Id: set.m,v 1.5 2008/02/25 18:08:49 ingo Exp $

 HISTORY:     23-07-2007 Diepholz
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function tf = set(tf, varargin)
0002 % SET set timeformat properties.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SET set timeformat properties.
0007 %
0008 % CALL:        tf = set(tf, 'property', 'value');
0009 %              tf = set(tf, 'property', 'value', 'direct');
0010 %
0011 % EXAMPLES:    tt = set(tt, 'format_str',         'yyyy.dd.mm HH:MM:SS AM');
0012 %              tt = set(tt, 'format_nr',           0);
0013 %              tt = set(tt, 'default_matlab_str', 'yyyy-mm-dd HH:MM:SS');
0014 %              tt = set(tt, 'default_matlab_nr',   31);
0015 %              tt = set(tt, 'default_java_str',   'yyyy-MM-dd HH:mm:ss');
0016 %
0017 % VERSION:     $Id: set.m,v 1.5 2008/02/25 18:08:49 ingo Exp $
0018 %
0019 % HISTORY:     23-07-2007 Diepholz
0020 %                 Creation
0021 %
0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0023 
0024 %%% REMARK: This function don't use the generic set-function!!!
0025 
0026 VERSION       = '$Id: set.m,v 1.5 2008/02/25 18:08:49 ingo Exp $';
0027 CATEGORY      = 'Helper';
0028 
0029 timeformat_fields = fieldnames(tf);
0030 property_argin    = varargin;
0031 
0032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0033 %%% Check if this is a special call: default parameter list, cvs-version, category
0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0035 if ~isempty(varargin{1}) == 1 && ischar(varargin{1})
0036   in = varargin{1};
0037   if strcmp(in, 'Params')
0038     tf = GET_DEFAULT_PLIST;
0039     return
0040   elseif strcmp(in, 'Version')
0041     tf = VERSION;
0042     return
0043   elseif strcmp(in, 'Category')
0044     tf = CATEGORY;
0045     return
0046   end
0047 end
0048 
0049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0050 %%% Convert a plist into a key/value set
0051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0052 if nargin >= 2 && isa(property_argin{1}, 'plist')
0053   pl        = property_argin{1};
0054   property_argin = {};
0055   for ii = 1:nparams(pl)
0056     %% The 'key' name of a plist/param is always stored with upper case
0057     %% characters. To set a ao property with this key we have to lower the
0058     %% 'key' characters.
0059     property_argin{end+1} = lower(pl.params(ii).key);
0060     property_argin{end+1} =       pl.params(ii).val;
0061   end
0062 end
0063 
0064 if (nargout ~= 0)
0065 
0066   compute = true;
0067   if nargin == 4 && strcmp(varargin{3}, 'direct')
0068     compute = false;
0069   end
0070 
0071   while length(property_argin) >= 2
0072     prop = property_argin{1};
0073     val  = property_argin{2};
0074     property_argin = property_argin(3:end);
0075 
0076     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0077     % Set the format string
0078     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0079     if (strcmp(prop, 'format_str')) && (compute)
0080       if ischar(val)
0081         tf.format_str = val;
0082         if strcmp(tf.format_str, tf.default_matlab_str)
0083           tf.format_nr = tf.default_matlab_nr;
0084         else
0085           tf.format_nr = -1;
0086         end
0087       else
0088         error('### Please use for %s a format-string', tf.(field));
0089       end
0090 
0091     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0092     % Set the format number
0093     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0094     elseif (strcmp (prop, 'format_nr')) && (compute)
0095       if isnumeric(val)
0096         tf.format_nr = val;
0097         if (tf.format_nr == tf.default_matlab_nr)
0098           tf.format_str = tf.default_matlab_str;
0099         else
0100           tf.format_str = '';
0101         end
0102       else
0103         error('### Please use for %s a matlab format-number', tf.(field));
0104       end
0105     elseif (strcmp(prop, {'default_matlab_str', ...
0106         'default_matlab_nr',  ...
0107         'default_java_str'}))
0108       error('### Do not set one of the default values. Only the time constructor should set this values.');
0109     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0110     % Set all other properties
0111     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0112     else
0113       try
0114         tf.(prop) = val;
0115       catch
0116         error('### ''%s'' is not a valid %s-object property.', prop, class(tf));
0117       end
0118     end
0119 
0120   end
0121 
0122 else
0123   display(tf);
0124   error('\n### No output variable!\n### Please use: %s = set(%s, ''key'', ''value'');', inputname(1), inputname(1));
0125 end
0126 
0127 
0128 function default_plist = GET_DEFAULT_PLIST
0129 default_plist =  plist('format_str',         '', ...
0130                        'format_nr',          -1, ...
0131                        'default_matlab_str', '', ...
0132                        'default_matlab_nr',  -1, ...
0133                        'default_java_str',   '');
0134 
0135 
0136

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003