Home > classes > @pole > pole.m

pole

PURPOSE ^

POLE construct a pole object.

SYNOPSIS ^

function p = pole(varargin)

DESCRIPTION ^

 POLE construct a pole object.

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

 DESCRIPTION:  POLE construct a pole object.

 CONSTRUCTORS: p = pole(f);
               p = pole(f,q);

 VERSION:      $Id: pole.m,v 1.13 2007/10/22 12:04:53 ingo Exp $

 HISTORY:      02-04-2007 M Hewitson
                  Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function p = pole(varargin)
0002 % POLE construct a pole object.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION:  POLE construct a pole object.
0007 %
0008 % CONSTRUCTORS: p = pole(f);
0009 %               p = pole(f,q);
0010 %
0011 % VERSION:      $Id: pole.m,v 1.13 2007/10/22 12:04:53 ingo Exp $
0012 %
0013 % HISTORY:      02-04-2007 M Hewitson
0014 %                  Creation
0015 %
0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0017 
0018 VERSION  = '$Id: pole.m,v 1.13 2007/10/22 12:04:53 ingo Exp $';
0019 
0020 %%%%%%%%%%%%%%%%%%%%%%%%   define pole properties   %%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022   function p = init()
0023     p.name    = 'not defined';
0024     p.f       = NaN;
0025     p.q       = NaN;
0026     p.ri      = NaN;
0027     p.version = VERSION;
0028     p.created = time;
0029     p         = class(p, 'pole');
0030   end
0031 
0032 %%%%%%%%%%%%%%%%%%%%%%%%%%   Create pole object   %%%%%%%%%%%%%%%%%%%%%%%%%%%
0033 
0034 %%%%%%%%%%   p = pole()   %%%%%%%%%%
0035 if nargin == 0
0036 
0037   p = init();
0038 
0039 elseif nargin == 1
0040 
0041   %%%%%%%%%% Create from XML fragment %%%%%%%%%%%
0042   if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl')
0043     p = fromxml(varargin{1});
0044 
0045   %%%%%%%%% From File %%%%%%%%%%%%
0046   elseif ischar(varargin{1})
0047 
0048     filename = varargin{1};
0049     [path, name, ext, vers] = fileparts(filename);
0050     switch ext
0051       case '.mat'
0052         p = load(filename);
0053       case '.xml'
0054         p = xmlparse(pole, filename);
0055       otherwise
0056         error('### Unknown file type.');
0057     end
0058 
0059   %%%%%%%%%%   p = pole(number)           %%%%%%%%%%
0060   %%%%%%%%%%   p = pole(complex number)   %%%%%%%%%%
0061   elseif isnumeric(varargin{1})
0062 
0063     p = init();
0064 
0065     if isreal(varargin{1})
0066       p.name    = 'real pole';
0067       p.f       = varargin{1};
0068       p.q       = NaN;
0069       p.ri      = pfq2ri(p.f);
0070     else
0071       p.name     = 'complex pole';
0072       [p.f, p.q] = pri2fq(varargin{1});
0073       p.ri      = [varargin{1} conj(varargin{1})];
0074     end
0075 
0076   %%%%%%%%%%   p = pole(struct)   %%%%%%%%%%
0077   elseif isstruct(varargin{1})
0078 
0079     p = init();
0080 
0081     fields = fieldnames(varargin{1});
0082     for ii = 1:length(fields)
0083       field = fields{ii};
0084       try
0085         p.(field) = varargin{1}.(field);
0086       catch
0087           error('### The field ''%s'' in the struct is not a pole property.', field)
0088       end
0089     end
0090 
0091   %%%%%%%%%%   p = pole(plist)   %%%%%%%%%%
0092   elseif isa(varargin{1}, 'plist')
0093 
0094     p = init();
0095     p = poleFromPlist(p, varargin{1});
0096 
0097   %%%%%%%%%%   p = pole(pole)   %%%%%%%%%%
0098   elseif isa(varargin{1}, 'pole')
0099     p = varargin{1};
0100   else
0101     error('### unknown constructor method for pole class.');
0102   end
0103 
0104 elseif nargin == 2
0105   %%%%%%%%%%% From DATABASE
0106   if isa(varargin{1}, 'database')
0107     p = retrieve(varargin{1}, varargin{2:end});
0108   %%%%%%%%%%   p = pole(f, q)   %%%%%%%%%%
0109   elseif isnumeric(varargin{1}) && isnumeric(varargin{2})
0110 
0111     p      =  init();
0112     if isnan(varargin{2})
0113       p.name = 'real pole';
0114     else
0115       p.name = 'complex pole';
0116     end
0117     p.f    =  varargin{1};
0118     p.q    =  varargin{2};
0119     p.ri   =  pfq2ri(p.f, p.q);
0120 
0121   else
0122     error('### unknown constructor method for pole class.');
0123   end
0124 
0125 end
0126 
0127 %--------------------------------------------------------------------------
0128 % construct a pole from plist
0129 %
0130 function p = poleFromPlist(p, pl)
0131 
0132   f  = find(pl, 'f');
0133   q  = find(pl, 'q');
0134   ri = find(pl, 'ri');
0135 
0136   name    = find(pl, 'name');
0137   version = find(pl, 'version');
0138   created = find(pl, 'created');
0139 
0140   if ~isempty(f)
0141     if ~isempty(q)
0142       % complex pole
0143       if isnan(q)
0144         p.name    = 'real pole';
0145       else
0146         p.name    = 'complex pole';
0147       end
0148       p.f       = f;
0149       p.q       = q;
0150       p.ri      = pfq2ri(p.f, p.q);
0151 
0152     else
0153       % real pole
0154       p.name    = 'real pole';
0155       p.f       = f;
0156       p.q       = -1;
0157       p.ri      = pfq2ri(p.f);
0158 
0159     end
0160   elseif ~isempty(ri)
0161     % complex pole
0162     p.name    = 'complex pole';
0163     [p.f, p.q] = pri2fq(ri);
0164     p.ri      = ri;
0165 
0166   else
0167     error('### unknown constructor method for pole class.');
0168   end
0169 
0170   % Set other the properties in the plist
0171   if ~isempty(name)
0172     p.name = name;
0173   end
0174   if ~isempty(version)
0175     p.version = version;
0176   end
0177   if ~isempty(created)
0178     p.created = created;
0179   end
0180 
0181 
0182 end
0183 
0184 end % function p = pole(varargin)
0185 
0186 % END

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003