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

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