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.3 2008/01/15 17:36:36 ingo Exp $

 HISTORY:     23-07-2007 Diepholz
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

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.3 2008/01/15 17:36:36 ingo Exp $
0018 %
0019 % HISTORY:     23-07-2007 Diepholz
0020 %                 Creation
0021 %
0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0023 
0024 VERSION  = '$Id: set.m,v 1.3 2008/01/15 17:36:36 ingo Exp $';
0025 
0026 % Check if this is a call for parameters
0027 if nargin == 2
0028   if isa(tf, 'timeformat') && ischar(varargin{1})
0029     in = char(varargin{1});
0030     if strcmp(in, 'Params')
0031       tf = plist();
0032       return
0033     elseif strcmp(in, 'Version')
0034       tf = VERSION;
0035       return
0036     end
0037   end
0038 end
0039 
0040 if (nargout ~= 0)
0041 
0042   compute = true;
0043   if nargin == 4 && strcmp(varargin{3}, 'direct')
0044     compute = false;
0045   end
0046 
0047   property_argin = varargin;
0048 
0049   fields = fieldnames(tf);
0050 
0051   while length(property_argin) >= 2
0052     prop = property_argin{1};
0053     val  = property_argin{2};
0054     property_argin = property_argin(3:end);
0055 
0056     if ~ismember(prop, fields)
0057       error(['### ', prop, ' is not a valid time property.']);
0058     else
0059 
0060       % Set the format string
0061       if (strcmp(prop, 'format_str')) && (compute)
0062         if ischar(val)
0063           tf.format_str = val;
0064           if strcmp(tf.format_str, tf.default_matlab_str)
0065             tf.format_nr = tf.default_matlab_nr;
0066           else
0067             tf.format_nr = -1;
0068           end
0069         else
0070           error('### Please use for %s a format-string', tf.(field));
0071         end
0072 
0073       % Set the format number
0074       elseif (strcmp (prop, 'format_nr')) && (compute)
0075         if isnumeric(val)
0076           tf.format_nr = val;
0077           if (tf.format_nr == tf.default_matlab_nr)
0078             tf.format_str = tf.default_matlab_str;
0079           else
0080             tf.format_str = '';
0081           end
0082         else
0083           error('### Please use for %s a matlab format-number', tf.(field));
0084         end
0085       elseif (strcmp(prop, {'default_matlab_str', ...
0086                             'default_matlab_nr',  ...
0087                             'default_java_str'}))
0088         error('### Do not set one of the default values. Only the time constructor should set this values.');
0089       else
0090         tf.(prop) = val;
0091       end
0092 
0093     end
0094 
0095 
0096   end
0097 
0098 else
0099   if ischar(varargin{2})
0100     error('### please use: %s = set(%s, ''%s'', ''%s'');', ...
0101                         inputname(1), ...
0102                         inputname(1), ...
0103                         varargin{1},  ...
0104                         varargin{2});
0105   elseif isnumeric(varargin{2})
0106     error('### please use: %s = set(%s, ''%s'', %d);', ...
0107                         inputname(1), ...
0108                         inputname(1), ...
0109                         varargin{1},  ...
0110                         varargin{2});
0111   else
0112     error('### please use: %s = set(%s, ''key'', ''value'');', ...
0113                         inputname(1), ...
0114                         inputname(1));
0115   end
0116 end

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