0001 function tf = set(tf, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
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
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
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
0057
0058
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
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
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
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